【解题报告】Codeforces Good Bye 2016
来源:互联网 发布:手写图片识别软件 编辑:程序博客网 时间:2024/04/30 09:54
A. New Year and Hurry(Codeforces 750A)
思路
先预处理出解每道题所用的时间
代码
#include <bits/stdc++.h>using namespace std;const int maxn = 100;int n, k, d, a[maxn];int main() {// freopen("data.txt", "r", stdin); for(int i = 1; i <= 10; i++) { a[i] = 5 * i; } for(int i = 1; i <= 10; i++) { a[i] += a[i-1]; } cin >> n >> k; d = 240 - k; for(int i = n; i >= 0; i--) { if(d >= a[i]) { cout << i << endl;; break; } } return 0;}
B. New Year and North Pole(Codeforces 750B)
思路
在本题中,经度(东西走向)不是我们关心的量,纬度(南北走向)才是我们关心的量。于是我们可以把纬度抽象为一个
代码
#include <bits/stdc++.h>using namespace std;const int np = 0, sp = 20000;int n;bool ok() { int t, cur = 0; string s; for(int i = 1; i <= n; i++) { cin >> t >> s; if(s == "South") { cur += t; if(cur > sp) { return false; } } else if(s == "North") { cur -= t; if(cur < np) { return false; } } else { if(cur == np || cur == sp) { return false; } } } return (cur == np);}int main() {// freopen("data.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); cin >> n; puts(ok() ? "YES" : "NO"); return 0;}
C. New Year and Rating(Codeforces 750C)
思路
首先因为
其次,我们可以维护一个区间
代码
#include <bits/stdc++.h>using namespace std;const int maxn = 2e5 + 10, INF = 1e9;bool ok = true, two = false;int n, l, r, num[maxn], d[maxn];int main() {// freopen("data.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> num[i] >> d[i]; if(d[i] == 2) { two = true; } } // 当主角一直在Div1中 if(two == false) { cout << "Infinity" << endl; return 0; } // 设置初始区间 if(d[1] == 1) { l = 1900; r = INF; } else { l = -INF; r = 1899; } for(int i = 1; i <= n; i++) { // 动态维护区间信息 l += num[i]; r += num[i]; if(l < -INF) { l = -INF; } if(r > INF) { r = INF; } // 根据Div的变化情况修正区间 if(i < n) { // 当主角从Div2到Div2而且rating上升时 if(d[i] == 2 && d[i+1] == 2 && num[i] >= 0) { r = min(r, 1899); } // 当主角从Div1到Div1而且rating下降时 if(d[i] == 1 && d[i+1] == 1 && num[i] < 0) { l = max(l, 1900); } // 当主角从Div1到Div2而且rating下降时 if(d[i] == 1 && d[i+1] == 2 && num[i] < 0) { r = min(r, 1899); } // 当主角从Div2到Div1而且rating上升时 if(d[i] == 2 && d[i+1] == 1 && num[i] >= 0) { l = max(l, 1900); } // 以下两种情况不可能发生 if(d[i] == 1 && d[i+1] == 2 && num[i] >= 0) { ok = false; break; } if(d[i] == 2 && d[i+1] == 1 && num[i] <= 0) { ok = false; break; } // 剩余两种情况不用修正 } // 出现了非法区间 if(l > r) { ok = false; break; } } if(ok == false) { cout << "Impossible" << endl; } else if(r >= INF) { cout << "Infinity" << endl; } else { cout << r << endl; } return 0;}
思路
上述的思路虽然比较严谨,但代码上过于冗杂。如果依状态转移的思想来看,题给的每行输入相当于状态的转移。换句话说,之前增加的
代码
#include <bits/stdc++.h>using namespace std;const int inf = 1e9;int n, tmp, d, l, r, del;int main() { scanf("%d", &n); l = -inf, r = inf; del = 0; for(int i = 0; i < n; i++) { scanf("%d%d", &tmp, &d); if(d == 1) { l = max(l, 1900 - del); } else { r = min(r, 1899 - del); } del += tmp; } if(l > r) { puts("Impossible"); } else if(r == inf) { puts("Infinity"); } else { printf("%d\n", r + del); } return 0;}
D. New Year and Fireworks(Codeforces 750D)
思路
看到图中的类似二叉树的结构,首先想到的是搜索(生成所有的状态(包括阶段信息,位置信息和方向信息)然后涂色),但是粗略估计
既然状态空间那么小,我们就可以用记忆化搜索来解决本题。在实现方面,可以用
代码
#include <bits/stdc++.h>using namespace std;// 记录八个方向的坐标变化的常量数组const int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};const int maxn = 35, maxc = 400;bool color[maxc][maxc], vis[maxn][maxc][maxc][10];int n, ans, t[maxn];// 记忆化搜索void dfs(int cur, int x, int y, int d) { int nx, ny, tx, ty, td; vis[cur][x][y][d] = true; // color // 为本格涂色 if(color[x][y] == false) { color[x][y] = true; ans++; } // 为之后直线运动轨迹上的格子涂色 nx = x; ny = y; for(int i = 1; i <= t[cur] - 1; i++) { nx += dx[d]; ny += dy[d]; if(color[nx][ny] == false) { color[nx][ny] = true; ans++; } } if(cur == n) { return; } // 生成向“右前方”分裂的烟花 td = (d + 1) % 8; tx = nx + dx[td]; ty = ny + dy[td]; if(vis[cur+1][tx][ty][td] == false) { dfs(cur + 1, tx, ty, td); } // 生成向“左前方”分裂的烟花 td = (d + 7) % 8; tx = nx + dx[td]; ty = ny + dy[td]; if(vis[cur+1][tx][ty][td] == false) { dfs(cur + 1, tx, ty, td); }}int main() {// freopen("data.txt", "r", stdin); scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &t[i]); } dfs(1, maxc / 2, maxc / 2, 0); printf("%d\n", ans); return 0;}
(其它题目略)
- 【解题报告】Codeforces Good Bye 2016
- Codeforces Good Bye 2014 解题报告 (A B C D)
- CodeForces Good Bye 2016
- Codeforces------Good Bye 2016
- codeforces Good Bye 2016
- codeforces Good Bye 2016
- Codeforces Good Bye 2016(部分题解)
- Codeforces Good Bye 2016部分题解
- CodeForces Good Bye 2013
- codeforces GOOD BYE 2013
- Codeforces Good Bye 2013
- Codeforces Good Bye 2014
- codeforces good bye 2014
- codeforces Good Bye 2014
- Codeforces Good Bye 2014
- Codeforces Good Bye 2013
- Codeforces Good Bye 2015
- Codeforces Good Bye 2013 ABCDE
- Windows下文字聊天的基本源代码
- 多媒体音频处理工具-PCM音频数据查看工具
- jekyll博客搭建
- Java中Runtime运行时环境机制总结
- hadoop部分异常处理
- 【解题报告】Codeforces Good Bye 2016
- Lattice系列FPGA入门相关1(Lattice系列FPGA简介)
- 警告:Spring ApplicationContext - Resource leak: 'context' is never closed的处理
- 这一年呐。。。
- spring-boot restful接口学习(1)
- Exjts 4.0 关于树与border布局显示的问题,急求结局
- 【C++解题报告】求组合数(定义函数)
- js post 清除REFERER 来路,全网首发
- Centos7 下禁用Mysql密码的强度加强validate_password插件