Codeforces Round #316 (Div. 2)
来源:互联网 发布:网络攻防实验报告 编辑:程序博客网 时间:2024/05/22 06:16
A http://codeforces.com/contest/570/problem/A
简单题
int n, m;long long cnt[1000];struct node{ long long nb; long long sum;}res[1000],ans[1000];bool cmp(node a, node b){ if (a.sum != b.sum) return a.sum > b.sum; else return a.nb < b.nb;}bool cmp2(int a, int b){ return a > b;}int main(){ while (~scanf("%d%d", &n, &m)) { memset(ans, 0, sizeof(ans)); memset(cnt, 0, sizeof(cnt)); long long t; for (int i = 1; i <= m; i++) { memset(res, 0, sizeof(res)); for (int j = 1; j <= n; j++) { scanf("%lld",&t); res[j].sum += t; res[j].nb = j; } sort(res + 1, res + 1 + n, cmp); cnt[res[1].nb]++; } long long MAX = -1; for (int i = 0; i <= n; i++) MAX = max(MAX, cnt[i]); for (int i = 0; i <= n; i++) { if (cnt[i] == MAX) { printf("%d\n", i); break; } } } return 0;}
B http://codeforces.com/contest/570/problem/B
简单题
int n, m;int main(){ while (~scanf("%d%d", &n, &m)) { if (n == 1 && m == 1) { printf("1\n"); continue; } int ans = n / 2; if (ans >= m) ans = m+1; else ans = m - 1; printf("%d\n",ans); } return 0;}
C http://codeforces.com/contest/570/problem/C
思路见代码
int n, m;char s[300010];int main(){ while (~scanf("%d%d", &n, &m)) { scanf("%s", s+1); int pos; char c[10]; int ans = 0; for (int i = 1; i < n; i++) if (s[i] == '.' && s[i + 1] == '.') ans++; while (m--) { scanf("%d%s", &pos, c); if (pos > 1 && s[pos] == '.' && s[pos - 1] == '.') ans--; if (pos + 1 <= n && s[pos] == '.' && s[pos + 1] == '.') ans--; s[pos] = c[0]; if (pos > 1 && s[pos] == '.' && s[pos - 1] == '.') ans++; if (pos + 1 <= n && s[pos] == '.' && s[pos + 1] == '.') ans++; printf("%d\n",ans); } } return 0;}
D http://codeforces.com/contest/570/problem/D
代码TLE了。。。之后改
int n, m;int deep[500010];int fa[500010];char s[500010];char ss[30] = {'a','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'};map<char, int>mp;vector<int> g[500010];void dfs(int x,int d){ if (deep[x] == d) mp[s[x]]++; for (int i = 0; i < g[x].size(); i++) { if (fa[g[x][i]] == x) dfs(g[x][i], d); }}int main(){ while (~scanf("%d%d", &n, &m)) { memset(fa, -1, sizeof(fa)); for (int i = 1; i <= n; i++) g[i].clear(); fa[1] = 1; deep[1] = 1; int max_deep = 1; int tmp; for (int i = 2; i <= n; i++) { scanf("%d", &tmp); g[tmp].push_back(i); fa[i] = tmp; deep[i] = deep[fa[i]] + 1; max_deep = max(max_deep, deep[i]); } scanf("%s", s + 1); int a, b; while (m--) { scanf("%d%d", &a, &b); if (b > max_deep) { puts("Yes"); continue; } if (deep[a] > deep[b]) { puts("Yes"); continue; } mp.clear(); dfs(a, b); int cnt = 0; for (int i = 1; i <= 26; i++) { if (mp[ss[i]] % 2 == 1) cnt++; if (cnt > 1) break; } //cout << " *** " << str << endl; if (cnt > 1) puts("No"); else puts("Yes"); } } return 0;}
0 0
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- 【codeforces】Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2)-C. Replacement
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2) A. Elections
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2)ProblemC
- Codeforces Round #316 (Div. 2) A. Elections
- Codeforces Round #316 (Div. 2) C. Replacement
- Codeforces Round #316 (Div. 2)A. Elections
- Codeforces Round #316 (Div. 2)(ABCD)
- 1.线程与进程概念性总结(初级)
- Swift详解之三----------函数(你想知道的都在这里)
- C语言主函数返回值问题:return type of 'main' is not 'int' [-Wmain]
- 图解classloader加载class的流程及自定义ClassLoader
- Java基础网络编程
- Codeforces Round #316 (Div. 2)
- OC_调用系统短信_邮件_电话
- Scala 深入浅出实战经典 第11讲:Scala中的apply实战详解
- hdu(5400)——Arithmetic Sequence(想法题)
- cocos2dx3.0戳青蛙游戏(打地鼠)
- 深入Java集合学习系列:HashSet的实现原理
- hdu 2095 find your present (2)
- Scala 深入浅出实战经典 第12讲:Scala中的继承:超类的构造、重写字段、重写方法代码实战
- iOS Cell异步图片加载优化,缓存机制详解。