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