Codeforces Good Bye 2016 题解
好久没有fst题了。。。比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完。。。然后C题fst掉了结果就掉rating 了。。。下面放题解
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 int main(){ 7 int n,k; 8 scanf("%d%d",&n,&k); 9 k=240-k; 10 for (int i=1;i<=n;i++) { 11 k-=i*5; 12 if (k<0) { 13 printf("%d\n",i-1); 14 return 0; 15 } 16 } 17 printf("%d\n",n); 18 return 0; 19 }
View Code
B. New Year and North Pole
题目大意:从北极点出发,按指令指示走,求指示是否合法,同时能否在最后走回北极点。
要求在北极点只能向南走,在南极点只能向北走。 直接模拟咯,然后判断是否在南北极点就完了。
Code:
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int main(){ 7 int n,d,t=0; 8 char o[20]; 9 scanf("%d",&n); 10 for (int i=1;i<=n;i++) { 11 scanf("%d%s",&d,o); 12 switch(o[0]) { 13 case 'S' : 14 t+=d; 15 break; 16 case'N': 17 t-=d; 18 break; 19 } 20 if (t<0||t>20000) {printf("NO\n");return 0;} 21 if (t==0||t==20000) { 22 if (o[0]=='E'||o[0]=='W') { 23 puts("NO\n");return 0; 24 } 25 } 26 } 27 if (t==0) printf("YES\n");else puts("NO"); 28 return 0; 29 }
View Code
C. New Year and Rating
题目大意:给定每场比赛的div以及rating升降,问结束时可能的最大rating
可以先2分分数然后判断是否合法,当然也可以求前缀和然后看div1的最低和div2的最高,然后吧div2的最高设为1899即可。(我TM吧数组开小了啊啊啊)
Code:
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define maxn 200010 7 int n,s[maxn],a[maxn]; 8 #define inf 1e9 9 int mn=inf,mx=-inf; 10 int main(){ 11 scanf("%d",&n); 12 for (int i=1;i<=n;i++) { 13 scanf("%d%d",s+i,a+i-1); 14 s[i]+=s[i-1]; 15 } 16 for (int i=0;i<n;i++){ 17 if (a[i]==1) mn=min(mn,s[i]); 18 else mx=max(mx,s[i]); 19 } 20 if (mn<=mx) { 21 puts("Impossible");return 0; 22 } 23 if (mx==-inf) { 24 puts("Infinity");return 0; 25 } 26 printf("%d\n",1899-mx+s[n]); 27 return 0; 28 }
View Code
D. New Year and Fireworks
题目大意:放烟花,每条烟火向一个方向前进$t_i$步然后向$45^\circ$扩散出2条烟火,求一共染了多少格子。
考虑直接模拟,由于最多有$2^{30}$条轨迹看上去并不可行,但我们可以发现向上下左右最大只能扩展150个方块,也就是说去重之后最多只有$300*300*4$条路径,可以接受。去重后模拟即可。
Code:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 #define maxn 330 7 int f[maxn][maxn][8]; 8 int b[maxn][maxn]; 9 int w[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}}; 10 int main(){ 11 f[160][160][0]=1; 12 int n; 13 scanf("%d",&n); 14 for (int l=1;l<=n;l++) { 15 int t; 16 scanf("%d",&t); 17 for (int i=1;i<=320;i++) 18 for (int j=1;j<=320;j++) 19 for (int k=0;k<8;k++) { 20 if (f[i][j][k]!=l) continue; 21 for (int l=1;l<=t;l++) 22 b[i+w[k][0]*l][j+w[k][1]*l]=1; 23 f[i+w[k][0]*t][j+w[k][1]*t][(k+1)%8]=f[i+w[k][0]*t][j+w[k][1]*t][(k-1+8)%8]=l+1; 24 } 25 } 26 int sum=0; 27 for (int i=1;i<=320;i++) 28 for (int j=1;j<=320;j++) sum+=b[i][j]; 29 printf("%d\n",sum); 30 return 0; 31 }
View Code
E. New Year and Old Subsequence
题目大意:给定一个字符串,每次求l~r中要删去多少字符才能使字符串中有2017而没有2016
很明显是个区间RMQ,考虑如何进行区间合并,考虑每个区间我们记录出现2017的所有子串需要删去的字符数(例如1的话就后面不能有6和7,但前面可以有0),然后就能非常复杂的转移了。。
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
转载于:https://www.cnblogs.com/New-Godess/p/6239946.html
Codeforces Good Bye 2016 题解相关推荐
- codeforces Good Bye 2022
codeforces Good Bye 2022 A. Koxia and Whiteboards 题解 根据提意,每次对a数组最小元素的操作就好了,因为n,m的范围比较小,所以没必要用优先对列. # ...
- Codeforces - Good Bye 2020
Codeforces - Good Bye 2020 前言 A - E 题解 2020的最后一场Codeforces,也算有点纪念意义吧- 赛时差1分钟调出e,一直被1<<i爆int迷惑了 ...
- Good Bye 2018题解
Good Bye 2018题解 题解 CF1091A [New Year and the Christmas Ornament] 打完cf都忘记写题解了qwq 题意就是:给你一些黄,蓝,红的球,满足蓝 ...
- codeforces div2 Not Assigning 题解
codeforces div2 Not Assigning 题解 原题链接 /* 题意:构造一棵素数树.素数树定义如下: 这颗树中任意一条边 or 任意两条边 权重之和为素数,每条边的权重自己分配. ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
- Codeforces Round#713 A-E题解
Codeforces Round 713 经典暴力模拟掉分场 本场链接: https://codeforces.com/contest/1512 个人博客の极致色彩简洁版题解: http://www. ...
- 【codeforces】【比赛题解】#940 CF Round #466 (Div. 2)
人生的大起大落莫过如此,下一场我一定要回紫. [A]Points on the line 题意: 一个直线上有\(n\)个点,要求去掉最少的点,使得最远两点距离不超过\(d\). 题解: 暴力两重fo ...
- 【codeforces】【比赛题解】#849 CF Round #431 (Div.2)
cf的比赛越来越有难度了--至少我做起来是这样. 先看看题目吧:点我. 这次比赛是北京时间21:35开始的,算是比较良心. [A]奇数与结束 "奇数从哪里开始,又在哪里结束?梦想从何处起航, ...
最新文章
- JAVA Web项目中所出现错误及解决方式合集(不断更新中)
- startup mount报错:invalid value given for the diagnostic_dest init.ora parameter
- 【HDU】Flipper 3328 (stack + 模拟 + 英语阅读)
- 网站优化之如何筛选更正确高质量的关键词?
- Maven下载安装与配置环境变量与配置本地仓库
- java 7.函数-递归_带有谓词的Java中的函数样式-第2部分
- 中交叉的线_表现力一绝!用交叉线构图拍出来的照片,竟然可以这么吸睛!
- [福建集训2011][LOJ10111]相框
- vba 当前文件名_值得学习和珍藏的VBA常用编程代码语句
- 在VS2013平台下如何快速解决c++代码内存泄漏问题
- 生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库?
- linux eclipse stm32,在ubuntu下利用eclipse搭建stm32开发环境和st-link调试
- Python学习笔记:目录与文件操作
- oracle DML错误日志(笔记)
- poj 1469(二分图最大匹配)
- Java中的Flyweight设计模式
- 基于公司云平台的素材归档系统(一)
- 【离散数学】图论 第七章(8) 运输网络、流和割、Ford-Fulkerson定理
- C# string 保留数字英文字母
- P2184 贪婪大陆(线段树或树状数组+思维)
热门文章
- SOCK_DGRAM(数据报套接字)与SOCK_STREAM(流套接口)的区别
- java项目使用mybatis
- oracle查询 :一个角色包括的系统权限,对象权限,Oracle有多少种角色,某个用户有什么角色
- Java Bag模型模拟
- python采集_Python3做采集
- Package ‘oniguruma’, required by ‘virtual:world’, not found
- 《好未来编程题》字符串中找出连续最长的数字串
- 软件设计原则(二)单一职责原则 -Single Responsibility Principle
- Scrapy入门(二)创建Scrapy项目
- golang bloom filter实现