Codeforces Round #556 (Div. 2)
没想到平成年代最后一场cf居然是手速场,幸好拿了个小号娱乐不然掉分预定 (逃
题目链接:http://codeforces.com/contest/1150
A:
傻题。
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define int_inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 const int maxn = 1e2 + 10; 41 int n, m, r, minn = 2000, maxx = 0; 42 43 int main() 44 { 45 scanf("%d%d%d", &n, &m, &r); 46 rep1(i, 1, n) 47 { 48 int x; scanf("%d", &x); minn = min(minn, x); 49 } 50 rep1(i, 1, m) 51 { 52 int x; scanf("%d", &x); maxx = max(maxx, x); 53 } 54 if (maxx > minn) printf("%d\n", maxx * (r / minn) + r % minn); 55 else printf("%d\n", r); 56 return 0; 57 }
View Code
B:
乍一看以为要搜,其实根本不需要,n^2填进去判断就完事了 (看通过人数就能猜到根本不用搜。
至于为什么可以这样,是因为跟紧密填充相关吗?
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define int_inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 const int maxn = 55; 41 int a[maxn][maxn], n, solved = 0; 42 char s[maxn]; 43 44 int check() 45 { 46 rep1(i, 1, n) 47 rep1(j, 1, n) 48 if (!a[i][j]) return 0; 49 return 1; 50 } 51 52 int putable(int x, int y) 53 { 54 if (x == 1 || x == n || y == 1 || y == n) return 0; 55 if (a[x - 1][y] || a[x + 1][y] || a[x][y - 1] || a[x][y + 1] || a[x][y]) return 0; 56 return 1; 57 } 58 59 int main() 60 { 61 scanf("%d", &n); 62 rep1(i, 1, n) 63 { 64 scanf("%s", s + 1); 65 rep1(j, 1, n) 66 if (s[j] == '#') a[i][j] = 1; else a[i][j] = 0; 67 } 68 rep1(i, 2, n - 1) 69 { 70 rep1(j, 2, n - 1) 71 if (putable(i, j)) 72 { 73 a[i - 1][j] = a[i + 1][j] = a[i][j - 1] = a[i][j + 1] = a[i][j] = 1; 74 } 75 } 76 if (check()) puts("YES"); 77 else puts("NO"); 78 return 0; 79 }
View Code
C:
2e5质数筛贪心就完事了,优先满足最近的质数,先塞2再塞1,也有大佬说不用筛。
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define int_inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 const int maxn = 2e5 + 10; 41 int c1 = 0, c2 = 0, n, prime[maxn], p = 1, tot; 42 vector<int>ans; 43 44 bool valid[maxn]; 45 void getPrime(int n, int &tot, int ans[maxn]) 46 { 47 tot = 0; 48 memset(valid, 1, sizeof(valid)); 49 for (int i = 2; i <= n; i++) 50 { 51 if (valid[i]) ans[++tot] = i; 52 for (int j = 1; (j <= tot) && (i * ans[j] <= n); j++) 53 { 54 valid[i * ans[j]] = false; 55 if (i % ans[j] == 0) break; 56 } 57 } 58 } 59 60 int main() 61 { 62 getPrime(2e5, tot, prime); 63 ans.clear(); 64 scanf("%d", &n); 65 rep1(i, 1, n) 66 { 67 int x; scanf("%d", &x); 68 if (x & 1) c1++; else c2++; 69 } 70 int curr = 0; 71 while (c1 || c2) 72 { 73 if (prime[p] - curr > 2 && c2) 74 { 75 ans.pb(2); c2--; curr += 2; 76 } 77 else if (prime[p] - curr == 2 && c2) 78 { 79 ans.pb(2); c2--; p++; curr += 2; 80 } 81 else if (prime[p] - curr == 1 && c1) 82 { 83 ans.pb(1); c1--; p++; curr += 1; 84 } 85 else 86 { 87 if (c2) 88 { 89 ans.pb(2); c2--; curr += 2; 90 } 91 else if (c1) 92 { 93 ans.pb(1); c1--; curr += 1; 94 } 95 } 96 } 97 for (auto i : ans) printf("%d ", i); 98 return 0; 99 }
View Code
D:
把全场人卡死的dp,直到比赛结束都只有不到20个人过了.
设f[i][j][k]表示第1个串匹配到i,第2个串匹配到j,第3个串匹配到k所用的最小长度,然后每次添加一个字符可以O(250^2)转移另外两维的状态即可。
复杂度:O(q*250^2)
E:
给定一个括号序列,每个括号序列可以唯一生成一棵有根树。给出q次询问,每次询问交换上次得到的括号序列中某两个括号的位置(保证交换之后仍然可以生成一棵有根树)。输出交换之后得到的有根树的直径。
一看就是线段树可以做的题。
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define int_inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 const int maxn = 2e5 + 10; 41 char s[maxn]; 42 43 struct Node 44 { 45 int sum, pmx, lmx, minn, maxx, d; 46 Node() {} 47 Node(int a, int b, int c, int d, int e, int f) 48 { 49 sum = a; pmx = b; lmx = c; minn = d; maxx = e; d = f; 50 } 51 }; 52 53 //ostream &operator<<(ostream &os, const Node &rhs) 54 //{ 55 // os << rhs.sum << " " << rhs.pmx << " " << rhs.lmx << " " << rhs.minn << " " << rhs.maxx << " " << rhs.d; 56 // return os; 57 //} 58 59 Node segT[maxn << 2]; 60 61 void maintain(int curPos) 62 { 63 segT[curPos].sum = segT[lson].sum + segT[rson].sum; 64 segT[curPos].pmx = max(segT[lson].pmx, max(segT[rson].maxx - 2 * segT[lson].minn + segT[lson].sum, segT[rson].pmx - segT[lson].sum)); 65 segT[curPos].lmx = max(segT[lson].lmx, max(segT[rson].lmx - segT[lson].sum, segT[lson].maxx - 2 * segT[rson].minn - 2 * segT[lson].sum)); 66 segT[curPos].minn = min(segT[lson].minn, segT[rson].minn + segT[lson].sum); 67 segT[curPos].maxx = max(segT[lson].maxx, segT[rson].maxx + segT[lson].sum); 68 segT[curPos].d = max(max(segT[lson].d, segT[rson].d), max(segT[lson].maxx + segT[rson].pmx - segT[lson].sum, segT[lson].lmx + segT[lson].sum + segT[rson].maxx)); 69 } 70 71 void build(int curPos, int curL, int curR) 72 { 73 if (curL == curR) 74 { 75 int x = s[curL] == '(' ? 1 : -1; 76 segT[curPos] = Node(x, -x, -x, x, x, 0); 77 // cout << segT[curPos] << endl; 78 return; 79 } 80 int mid = curL + curR >> 1; 81 build(lson, curL, mid); build(rson, mid + 1, curR); 82 maintain(curPos); 83 } 84 85 void update(int pos, int curPos, int curL, int curR) 86 { 87 if (curL == curR) 88 return build(curPos, curL, curR); 89 int mid = curL + curR >> 1; 90 if (pos <= mid) 91 update(pos, lson, curL, mid); 92 else 93 update(pos, rson, mid + 1, curR); 94 maintain(curPos); 95 } 96 97 int main() 98 { 99 int n, m; scanf("%d%d", &n, &m); 100 scanf("%s", s + 1); 101 n = n * 2 - 2; 102 build(1, 1, n); 103 printf("%d\n", segT[1].d); 104 while (m--) 105 { 106 int x, y; scanf("%d%d", &x, &y); 107 swap(s[x], s[y]); 108 update(x, 1, 1, n); update(y, 1, 1, n); 109 printf("%d\n", segT[1].d); 110 } 111 return 0; 112 }
View Code
转载于:https://www.cnblogs.com/JHSeng/p/10795255.html
Codeforces Round #556 (Div. 2)相关推荐
- Codeforces Round #556 (Div. 1Div. 2)
Codeforces Round #556 (Div. 1&&Div. 2) 题号 题目 知识点 A Stock Arbitraging 贪心 B Tiling Challenge 贪 ...
- Codeforces Round #556 (Div. 1)
Codeforces Round #556 (Div. 1) A. Prefix Sum Primes 给你一堆1,2,你可以任意排序,要求你输出的数列的前缀和中质数个数最大. 发现只有\(2\)是偶 ...
- Codeforces Round #556 (Div. 1) B. Three Religions
链接 https://codeforces.com/contest/1149/problem/B 题解 当时没想出来,但其实顺着当时的某个思路想下去也许能够得到正解 首先考虑给定三个字符串,我怎么判定 ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
- Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...
- Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...
- Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...
最新文章
- 如何获取微信API的Access Token
- 【原创】linux 下远程连接windows桌面
- [SoapUI] 在SoapUI中通过Groovy脚本执行window命令杀掉进程
- FSR 是提高性能和视觉效果
- Linux系统中 安装Vmware Toolst工具
- python 映射网络驱动器_用Delphi实现网络驱动器的映射和断开
- Genius‘s Gambit【学习进度条1】
- 我的大学之路---《大学之路》读后感
- C语言程序设计苏小红课后习题答案7.14.5
- 【CTA】CTA认证要求打开日历时提示联系人权限确认
- Java Swing编写的一个猜拳小游戏
- 解决WPS及office二次开发接口无法注册的问题
- 2022 年最佳开源软件出炉
- 饼图指北(Pie Chart)
- 我为什么坚信光触媒的未来?
- VMware Fusion 13.0 OEM BIOS Version
- 上帝向我们所怀的意念
- Soft-RoCE部署及通信测试
- 【缺陷检测】基于matlab AlexNet和SVM异常螺母检测【含Matlab源码 2147期】
- 盘一盘 Python 特别篇 19 - 天数计数|年限
热门文章
- Maven修改默认本地资源库文件夹
- css禁用鼠标点击事件
- Hibernate和JDBC、EJB比较
- SCROLLINFO结构详解
- [转贴]超过80%的80后大学生不知道自己将来要干什么
- c# 计算点到线段的距离
- gdi按钮重绘背景黑色_PS快速抠图换背景教程 PS怎么抠图放在另一张图 这个方法简单万能...
- vue-ueditor 后端配置项没有正常加载_揭秘Gannt后端集成问题该如何解决
- mysql 5.5 主从双向同步,请教mysql 定时 双向 主从同步問題
- 结合泛函极值_泛函极值及变分法教程.doc