一次无数坑的CF 。。Orz...
A. Jzzhu and Children
题目:http://codeforces.com/contest/450/problem/A
题意:有n个人,每个人每次给m个糖,给出那些人需要的糖果数,若糖果数不够则排到队伍后面。求出最后拿够糖果的人是谁。
一开始以为是求出最大值,反例:n=2,m=2,人 6,5;则最后拿到糖果的是人2;
数据量只有100,则直接模拟即可。
CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int a[105];
int n,m;
bool check()
{
for(int ii=0;ii<n;ii++)
{
if(a[ii]>0) return false;
}
return true;
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
int maxn=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
maxn=max(a[i],maxn);
}
int i=0;
while(1)
{
//puts("1");
for(i=0;i<n;i++)
{
a[i]-=m;
if(check())
break;
}
if(check()) break;
}
if(maxn > m) printf("%d\n",i+1);
else printf("%d\n",n);
}
return 0;
}
B. Jzzhu and Sequences
题目:http://codeforces.com/contest/450/problem/B
题意:f1 = x, f2 = y, f(i) = f(i-1) + f (i+1); 求出f (n) mod 1000000007;
思路:以6为一个循环节,注意 f (n) % mod有可能是负的 ,若为负,则还应该 + mod;
也有这样一个公式 (f(n) %mod + mod ) %mod;
CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define mod 1000000007;
typedef long long ll;
int main()
{
ll x,y;
int n;
ll f[8];
while(~scanf("%lld%lld",&x,&y))
{
f[1]=x;f[2]=y;
for(int i=3;i<=6;i++)
{
f[i]=f[i-1]-f[i-2];
}
f[0]=f[6];
scanf("%d",&n);
ll a=f[n%6] % mod;
a += mod;
a %= mod
printf("%I64d\n",a);
}
return 0;
}
C. Jzzhu and Chocolate
题目:http://codeforces.com/contest/450/problem/C
题意; 一个 n *m 的矩形,要求切k 刀,得到最小区域的最大范围。
思路:横切 k1 刀,竖切 k2 刀;则得到公式 ans= (n/ ( k1 + 1 ) * m / ( k2 + 1 ) ) = n*m / ( k1 * k2 +k + 1) , 则使得 k1 * k2 最小,即 k1 * ( k - k1 ) = -k1 * k1 + k * k1 ,则得到一个向下二次函数,则k1 应该是取最小值或者是最大值即可。记得判断限制条件 两边最多都只能切 (n- 1)或者是 ( m - 1 )。
CODE :
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n,m,k;
ll work()
{
if(m+n-2<k) return -1;
if(m+n-1 == k) return 1;
else
{
ll k1,k2,s1,s2,s; //k1尽可能的大或者是小
k2 = min(k,m-1);k1 = k-k2;
s = n/(k1+1)*(m/(k2+1));
k1 = min(k,n-1);s1 = n/(k1+1);
k2 = k-k1;s2 = m/(k2+1);
s = max(s1*s2,s);
return s;
}
}
int main()
{
//freopen("in.in","r",stdin);
while(~scanf("%lld%lld%lld",&n,&m,&k))
{
cout<<work()<<endl;
}
return 0;
}