time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th
box can hold at most xi boxes
on its top (we‘ll call xi the
strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second
and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more thanxi boxes
on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1?≤?n?≤?100).
The next line contains n integers x1,?x2,?...,?xn (0?≤?xi?≤?100).
Output
Output a single integer — the minimal possible number of piles.
Sample test(s)
input
3
0 0 10
output
2
input
5
0 1 2 3 4
output
1
input
4
0 0 0 0
output
4
input
9
0 1 0 2 0 1 1 2 10
output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
Fox and Box Accumulation
#include
#include
#include
#include
#include
#include
using namespace std;
int a[102];
int main()
{
int n,i,x;
while(cin>>n)
{
memset(a,0,sizeof(a));
for(i=0;i
cin>>x;
a[x]++;
}
int res=0;
while(1)
{
int flag=0;
for(i=0;i<=100;i++)
{
if(a[i])
{
flag=1;
break;
}
}
if(flag==0) break;
int step=0;
for(i=0;i<=100;i++)
{
if((a[i]>=1&&i==step)||(a[i]==1&&step {
a[i]--;
step++;
}
else if(step=2)
{
a[i]--;
step++;
//cout< //continue;
i--;
}
}
//for(i=0;i<=5;i++)
//cout< //cout<
}
cout<
return 0;
}
/*
3
0 0 10
5
0 1 2 3 4
4
0 0 0 0
9
0 1 0 2 0 1 1 2 10
7
0 2 2 2 3 4 5
*/
这个题目当时写的时候很拙计,虽然样例过了,但是自己随便写了组测试数据就过不了,然后就debug了好久。。
题目大意:让你构造一张图,使得结点1到结点2最短路走的方法有n种,当然1<=n<=10^9,当时突然灵光一闪就是素数分解,然后就开始写了,不过大于1000的素数是不可以的,因为要求最多只能用1000个点,然后题目有一句话说了:不会给没有答案的n。然后我就抱着庆幸的态度交了。不过最后被hack了。直到最后也没能想通。
Fox and Minimal path
#include
#include
#include
#include
#include
#include
using namespace std;
int mp[100][105];
int main()
{
int k;
int i,j;
while(cin>>k)
{
memset(mp,0,sizeof(mp));
mp[1][5]=1;
if(k&(1<<30))
{
mp[1][3]=1;
mp[1][4]=1;
}
j=3;
for(i=29;i>=1;i--)
{
mp[j][j+3]=1,mp[j][j+4]=1;
mp[j+1][j+3]=1,mp[j+1][j+4]=1;
mp[j+2][j+5]=1;
if(k&(1< {
mp[j+2][j+3]=1;
mp[j+2][j+4]=1;
}
j+=3;
}
mp[90][2]=1,mp[91][2]=1;
if(k&1) mp[92][2]=1;
cout<<92<
{
for(j=1;j<=92;j++)
{
if(mp[i][j]||mp[j][i]) cout<<"Y";
else cout<<"N";
}
cout<
}
return 0;
}
题目大意:看起来是个博弈题目,A,B分别拿物品,总共有n堆物品,每堆物品有s[i]个,从上面到下面分别放,每个物品各自的价&#20540;。A先拿物品,不过他每次只能选择从某一堆最上面拿出物品,而B每次只能选择从某一堆最下面拿出物品。A,B轮流拿物品,A,B都是最优选择使得总价&#20540;最大。问你
A,B最终得分。
Fox and Card Game
#include
#include
#include
#include
#include
#include
#include
using namespace std;
vector
int xf[105];
int main()
{
int n,s,x;
int i,j;
int a,b;
while(cin>>n)
{
for(i=1;i<=100;i++)
mq[i].clear();
a=0,b=0;
for(i=1;i<=n;i++)
{
cin>>s;
while(s--)
{
cin>>x;
mq[i].push_back(x);
}
}
int t=0;
for(i=1;i<=n;i++)
{
if(!(mq[i].size()&1))
{
for(j=0;j
else
{
for(j=0;j
for(;j
}
sort(xf,xf+t);
int flag=0;
for(i=t-1;i>=0;i--)
{
if(!flag)
{
a+=xf[i];
flag=1;
}
else
{
b+=xf[i];
flag=0;
}
}
cout< }
return 0;
}
/*
2
1 100
2 1 10
1
9 2 8 6 5 9 4 7 1 3
3
3 1 3 2
3 5 4 6
2 8 7
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
*/