标签:
A - Couple doubi
题意:桌上共有 k 个球,第i个球的值为 (1^i+2^i+...+(p-1)^i )mod p#include<stdio.h> int main() { int p,n; while(scanf("%d%d",&n,&p)!=EOF){ if((n/(p-1))%2) printf("YES\n"); else printf("NO\n"); } return 0; }
#include<stdio.h> #include<algorithm> #define N 100000 using namespace std; struct stu{ int time,level; }task[N+10],machine[N+10]; int cmp(stu a,stu b){ if(a.time==b.time) return a.level>b.level; return a.time>b.time; } int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF){ for(int i=1;i<=n;i++) scanf("%d%d",&machine[i].time,&machine[i].level); for(int i=1;i<=m;i++) scanf("%d%d",&task[i].time,&task[i].level); sort(machine+1,machine+1+n,cmp); sort(task+1,task+1+m,cmp); int j=1,cnt[105]={0},maxm=0; long long ans=0; for(int i=1;i<=m;i++){ while(j<=n&&task[i].time<=machine[j].time){ cnt[machine[j].level]++; j++; } for(int k=task[i].level;k<=100;k++){ if(cnt[k]){ maxm++; ans+=task[i].time*500+task[i].level*2; cnt[k]--; break; } } } printf("%d %I64d\n",maxm,ans); } return 0; }
#include<stdio.h> #include<string.h> #include<math.h> char Con[5][10]={"Dry","Dryish","Damp","Soggy"}; char We[5][10]={"Sunny","Cloudy","Rainy"}; double lePro[3][4]={0.6,0.2,0.15,0.05, 0.25,0.3,0.2,0.25, 0.05,0.10,0.35,0.50}; //叶子 double wePro[3][3]={0.5,0.375,0.125, 0.25,0.125,0.625, 0.25,0.375,0.375}; //天气 double init[3]={0.63,0.17,0.2}; double dp[55][3],pre[55][3]; int n,lePos[55]; void solve() { for(int i=0;i<3;i++) dp[1][i]=log(init[i])+log(lePro[i][lePos[1]]); for(int i=2;i<=n;i++){ for(int j=0;j<3;j++){ //今天天气 double maxp=-1e8; int pos=0; for(int k=0;k<3;k++){ //昨天天气 double temp=dp[i-1][k]+log(wePro[k][j])+log(lePro[j][lePos[i]]); if(temp>maxp){ maxp=temp; pos=k; } } dp[i][j]=maxp; pre[i][j]=pos; } } } int main() { int T; scanf("%d",&T); for(int k=1;k<=T;k++){ printf("Case #%d:\n",k); scanf("%d",&n); char con[10]; for(int i=1;i<=n;i++){ scanf("%s",con); for(int j=0;j<4;j++) if(strcmp(con,Con[j])==0){ lePos[i]=j; break; } } solve(); double maxp=-1e8; int ans[55]; for(int i=0;i<3;i++) if(dp[n][i]>maxp){ maxp=dp[n][i]; ans[n]=i; } for(int i=n-1;i>=1;i--) ans[i]=pre[i+1][ans[i+1]]; for(int i=1;i<=n;i++) printf("%s\n",We[ans[i]]); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/acm_code/article/details/46858779