标签:
USACO ORZ
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3625 Accepted Submission(s): 1212
Problem Description
Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.
I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N fence segments and must arrange them into a triangular pasture. Ms. Hei must use all the rails to create three sides of non-zero length. Calculating the number of different kinds of pastures, she can build that enclosed with all fence segments.
Two pastures look different if at least one side of both pastures has different lengths, and each pasture should not be degeneration.
Input
The first line is an integer T(T<=15) indicating the number of test cases.
The first line of each test case contains an integer N. (1 <= N <= 15)
The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)
Output
For each test case, output one integer indicating the number of different pastures.
Sample Input
Sample Output
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
set<long long> st;
int tt,n,a[16];
void dfs(int x,int y,int z,int step)
{
if(step==n)
{
if(x>y||y>z||x>z)
return ;
if(x&&y&&z&&(x+y)>z)
{
long long temp=10000000000LL*x+100000000LL*y+z;
st.insert(temp);
}
return ;
}
dfs(x+a[step],y,z,step+1);
dfs(x,y+a[step],z,step+1);
dfs(x,y,z+a[step],step+1);
}
int main()
{
scanf("%d",&tt);
while(tt--)
{
st.clear();
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
dfs(0,0,0,0);
printf("%d\n",st.size());
}
return 0;
}
Gunner
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 968 Accepted Submission(s): 426
Problem Description
Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i−th bird stands on the top of the i−th tree. The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the bird which stands in the tree with height H will falls.
Jack will shot many times, he wants to know how many birds fall during each shot.
a bullet can hit many birds, as long as they stand on the top of the tree with height of H.
Input
There are multiple test cases (about 5), every case gives n,m in the first line, n indicates there are n trees and n birds, m means Jack will shot m times.
In the second line, there are n numbers h[1],h[2],h[3],…,h[n] which describes the height of the trees.
In the third line, there are m numbers q[1],q[2],q[3],…,q[m] which describes the height of the Jack’s shots.
Please process to the end of file.
[Technical Specification]
1≤n,m≤1000000(106)
1≤h[i],q[i]≤1000000000(109)
All inputs are integers.
Output
For each q[i], output an integer in a single line indicates the number of birds Jack shot down.
Sample Input
Sample Output
1
0
1
Hint
Huge input, fast IO is recommended.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> mp;
int n,m;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
int main()
{
int x;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
{
x=read();
mp[x]++;
}
for(int i=0;i<m;i++)
{
x=read();
/*if(mp.find(x)==mp.end())
{
printf("0\n");
continue;
}*/
printf("%d\n",mp[x]);
mp[x]=0;
}
}
return 0;
}
暴力暴力暴力暴力暴暴暴!!!
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4398018.html