Codeforces Round #410 (Div. 2)
来源:互联网 发布:php 优惠券使用代码 编辑:程序博客网 时间:2024/05/16 15:43
题目:http://codeforces.com/contest/798
A. Mike and palindrome
#include <bits/stdc++.h>#define endl "\n"using namespace std;int main() {ios::sync_with_stdio(false);string str;cin >> str;int len = str.length();int cnt = 0;for(int i = 0; i < len/2; ++i) {if(str[i] != str[len-i-1]) {cnt++;}} if(cnt > 1 || (cnt == 0 && (len % 2 == 0))) {cout << "NO" << endl;}else {cout << "YES" << endl;}return 0;}
A. Mike and palindrome
#include <bits/stdc++.h>#define endl "\n"using namespace std;const int MAXN = 50 + 7;int main() { ios::sync_with_stdio(false); int n; cin >> n; string str[MAXN]; for(int i = 0; i < n; ++i) str[i] = ""; int ans = 1e8; for(int i = 0; i < n; ++i) { cin >> str[i]; } bool hasSol = true; for(int i = 0;i < n; ++i) { int tmp = 0; for(int j = 0; j < n; ++j) { if(i == j) continue; bool flag = false; for(int k = 0; k < str[j].length(); ++k) { if(str[j].substr(k, str[j].length() - k) + str[j].substr(0, k) == str[i]) { tmp += k; flag = true; break; } } if(!flag) { hasSol = false; break; } } if(!hasSol) { break; } ans = min(ans, tmp); } if(hasSol) { cout << ans << endl; } else { cout << "-1" << endl; } return 0;}
C. Mike and gcd problem
#include <bits/stdc++.h>#define endl "\n"using namespace std;const int MAXN = 100000 + 7;int num[MAXN];int gcd(int a, int b) { return a == 0 ? b : gcd(b%a, a);}int main() { ios::sync_with_stdio(false); //freopen("in.txt", "r", stdin); / freopen("out.txt", "w", stdout); int n, g = 0; while(cin >> n) { for(int i = 0; i < n; ++i) { cin >> num[i]; g = gcd(g, num[i]); } if(g > 1) { cout << "YES\n0" << endl; return 0; } int s = 0, c = 0; for(int i = 0; i <= n; ++i) { if(num[i] % 2 == 0) { if(c % 2 == 0) { s += c/2; } else { s += c/2 + 2; } c = 0; } else c++; } cout << "YES\n" << s << endl; } return 0;}
D. Mike and distribution
#include <bits/stdc++.h>#define endl "\n"using namespace std;const int MAXN = 100000 + 7;pair<pair<int, int>, int > p[MAXN];bool tag[MAXN];int main() { //freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);ios::sync_with_stdio(false);int n;cin >> n;for(int i = 1; i <= n; ++i) cin >> p[i].first.first;for(int i = 1; i <= n; ++i) cin >> p[i].first.second;for(int i = 1; i <= n; ++i) p[i].second = i;sort(p+1, p+n+1);int cnt = n - 1;if(n % 2 == 0) cnt = n-2;for(int i = 1; i <= cnt; i += 2) { if(p[i].first.second < p[i+1].first.second) { tag[p[i].second] = true; } else { tag[p[i+1].second] = true; }}cout << n/2 + 1 << endl;bool flag = false;for(int i = 1; i <= n; ++i) { if(!flag && !tag[i]) { flag = true; cout << i ; } else if(flag && !tag[i]) { cout << " " << i; }}return 0;}
0 0
- Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2)
- 【解题报告】Codeforces Round #410 (Div. 2)
- Codeforces Round #410 (Div. 2) 部分解析
- 【Codeforces Round #410 (Div. 2) B】暴力
- Codeforces Round #410 (Div. 2) 解题报告
- Codeforces Round #410 (Div. 2)(Codeforces 798 ABCD)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Java的switch是否支持String作为参数,还支持哪些类型?
- 双目相关
- OKHttpUtils使用介绍
- drawable2
- JSON数据格式
- Codeforces Round #410 (Div. 2)
- php 文字输入输出
- 笔记——ROM、PROM、EPROM、EEPROM、Flash ROM
- hihoCoder 1093 : 最短路径·三:SPFA算法
- Java for Web学习笔记(五三):Spring框架简介(2)一些准备
- hdu5242——Game(dfs贪心)
- springMVC 多文件上传
- 1011. A+B和C (15)
- springMVC