Codeforces Good Bye 2016 题解
2016-12-31 18:09
405 查看
好久没有fst题了。。。比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完。。。然后C题fst掉了结果就掉rating 了。。。下面放题解
直接模拟,求完成i道题所花时间$t_i+t\leq 240$ 的最大值
Code :
View Code
A. New Year and Hurry
题目大意:给定n道题和时间t,每完成第i道题需花$5*i$ 分钟,求在$240-t$分钟内完成的最大题数。直接模拟,求完成i道题所花时间$t_i+t\leq 240$ 的最大值
Code :
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define minn 210000 7 #define mink 19 8 int n,m; 9 char s[minn];/* 10 string a[15]; 11 a[0]="2"; 12 a[1]="0"; 13 a[2]="1"; 14 a[3]="7"; 15 a[4]="6"; 16 a[5]="20"; 17 a[6]="01"; 18 a[7]="17"; 19 a[8]="201"; 20 a[9]="017"; 21 a[10]="2017";*/ 22 struct node { 23 int f[11],s[5]; 24 }; 25 #define inf 1000000 26 node update(node x,node y) { 27 node ans; 28 for (int i=0;i<=10;i++) ans.f[i]=inf; 29 ans.f[0]=min(ans.f[0],min(x.f[0]+y.s[1],y.f[0]+x.s[0])); 30 ans.f[1]=min(ans.f[1],min(x.f[1]+y.s[2],x.s[1]+y.f[1])); 31 ans.f[2]=min(ans.f[2],min(x.f[2]+y.s[3]+y.s[4],x.s[2]+y.f[2])); 32 ans.f[3]=min(ans.f[3],min(x.f[3]+y.s[4],x.s[3]+y.f[3]+x.s[4])); 33 ans.f[5]=min(ans.f[5],min(x.f[5]+y.s[2],min(x.s[0]+y.f[5],x.f[0]+y.f[1]))); 34 ans.f[6]=min(ans.f[6],min(x.f[6]+y.s[3]+y.s[4],min(x.s[1]+y.f[6],x.f[1]+y.f[2]))); 35 ans.f[7]=min(ans.f[7],min(x.f[7]+y.s[4],min(x.s[2]+y.f[7],x.f[2]+y.f[3]))); 36 ans.f[8]=min(ans.f[8],min(min(x.f[8]+y.s[3]+y.s[4],x.s[0]+y.f[8]), 37 min(x.f[5]+y.f[2],x.f[0]+y.f[6]))); 38 ans.f[9]=min(ans.f[9],min(min(x.f[9]+y.s[4],x.s[1]+y.f[9]), 39 min(x.f[6]+y.f[3],x.f[1]+y.f[7]))); 40 ans.f[10]=min(ans.f[10],min(min(x.f[10]+y.s[4],x.s[0]+y.f[10]), 41 min(x.f[0]+y.f[9],min(x.f[5]+y.f[7],x.f[8]+y.f[3])))); 42 for (int i=0;i<5;i++) ans.s[i]=x.s[i]+y.s[i]; 43 return ans; 44 } 45 node build(int x) { 46 node ans; 47 memset(ans.s,0,sizeof(ans.s)); 48 for (int i=0;i<=10;i++) ans.f[i]=inf; 49 switch (x){ 50 case 2: 51 ans.s[0]=1;ans.f[0]=0;break; 52 case 0: 53 ans.s[1]=1;ans.f[1]=0;break; 54 case 1: 55 ans.s[2]=1;ans.f[2]=0;break; 56 case 7: 57 ans.s[3]=1;ans.f[3]=0;break; 58 case 6: 59 ans.s[4]=1;break; 60 } 61 return ans; 62 } 63 void print(node x){ 64 for (int i=0;i<=10;i++) printf("%d ",x.f[i]); 65 printf("\n"); 66 for (int i=0;i<=5;i++) printf("%d ",x.s[i]); 67 printf("\n"); 68 } 69 node f[mink][minn]; 70 int main(){ 71 scanf("%d%d",&n,&m); 72 scanf("%s",s+1); 73 for (int i=1;i<=n;i++) f[0][i]=build(s[i]-'0'); 74 for (int i=1;(1<<i)<=n;i++) 75 for (int j=1;j+(1<<i)-1<=n;j++){ 76 f[i][j]=update(f[i-1][j],f[i-1][j+(1<<(i-1))]); 77 } 78 for (int i=1;i<=m;i++) { 79 int l,r; 80 scanf("%d%d",&l,&r); 81 node ans; 82 int flag=0; 83 for (int j=mink-1;j>=0;j--) { 84 if (l+(1<<j)-1<=r) { 85 if (!flag) {ans=f[j][l];flag=1;} 86 else ans=update(ans,f[j][l]); 87 l+=(1<<j); 88 } 89 } 90 if (ans.f[10]==inf) printf("-1\n"); 91 else printf("%d\n",ans.f[10]); 92 } 93 return 0; 94 }
View Code
相关文章推荐
- codeforces Good Bye 2016
- Codeforces Good Bye 2016部分题解
- Codeforces Good Bye 2016 C.New Year and Rating//qduoj 三亿河老师的上分梦想
- codeforces Good Bye 2016
- Codeforces------Good Bye 2016
- codeforces Good Bye 2016-D New Year and Fireworks(dfs)
- Codeforces Good Bye 2016(部分题解)
- 【解题报告】Codeforces Good Bye 2016
- Codeforces Good Bye 2016 D 模拟搜索?
- Codeforces Good Bye 2016 C. New Year and Rating(模拟)
- codeforces Good Bye 2016-B New Year and North Pole
- codeforces Good Bye 2016-C New Year and Rating(二分)
- CodeForces Good Bye 2016 :C New Year and Rating、D New Year and Fireworks、E New Year and Old Subsequ
- Codeforces Good Bye 2016 D. New Year and Fireworks(bfs/dfs)
- Codeforces 656 B. Scrambled(April Fools Day Contest 2016)
- Codeforces Good Bye 2017
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A题 (String模拟)
- Codeforces 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest B题 (排序贪心)
- [2-SAT] Codeforces 668E #348 (VK Cup 2016 Round 2, Div. 1 Edition) E. Little Artem and 2-SAT
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy DP