您的位置:首页 > 其它

BestCoder Round #56 (div.2) (部分)

2015-09-20 10:32 239 查看
1001 Clarke and minecraft

水题一道,主要是数据处理

#include <cstdio>
#include <cstring>
#include <math.h>
#include <iostream>
using namespace std;
int num[505];
int type[505];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int a,b;
memset(num,0,sizeof num);
memset(type,-1,sizeof type);
int c=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
if(num[a]==0)
type[c++]=a;
num[a]+=b;
}
int ans=0,cnt=0;
for(int i=0;i<c;i++)
{
if(num[type[i]]%64)
cnt++;
cnt+=num[type[i]]/64;
// or * cnt+=ceil(num[type[i]]*1.0/64); *
}
if(cnt%36)
ans++;
ans+=cnt/36;
//or * ans+=ceil(cnt*1.0/36); *
printf("%d\n",ans);
}
return 0;
}


1002 Clarke and problem

dp水题,虽然我也不会,这道题思路主要是虽然|a[i]| <10e9,但是p只有1000,而且我们只需要p的倍数的数,所以a[i]%p不会对原结果产生影响,至于负数也是同样的道理,然后我们用f[(a[i]+j)%p]=dp[j] j{ 0~p-1}记录所得的和与p取余的余数的方法数,dp[j]=(dp[j]+f[j])%mod则是加上状态转移后的增量,最后输出dp[0]即可,由于j不会超过p所以省略%p的操作。

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mod=1e9+7;
int dp[1005];
int f[1005];
int a[1005];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,p;
scanf("%d%d",&n,&p);
memset(dp,0,sizeof dp);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
a[i]%=p;
while(a[i]<0) a[i]+=p;
}
memset(f,0,sizeof f);
dp[0]=1;//0也是一种方法
for(int i=1;i<=n;i++)
{
for(int j=0;j<p;j++)
{
f[(j+a[i])%p]=dp[j];
}
for(int j=0;j<p;j++)
dp[j]=(f[j]+dp[j])%mod;
// for(int j=0;j<p;j++)
//printf("%d %d\n",j,dp[j]);
}
printf("%d\n",dp[0]);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: