codeforce 632 前三题 找规律,暴力,字符串

http://codeforces.com/contest/632/standings


第一题:类似于猴子吃桃的问题。奇数的时候吃一半+1,偶数吃一半。

第二题:有两个组合,A组合是alice的,B组是Bob的。然后bob只能够反转一次,反转的长度任意,并只能从队伍最前面和队伍最后开始反转。因此只要预处理好,然后暴力解决就好了。

第三题:之前一直想着用cmp分类讨论,看了人家的代码,大牛真的是大牛啊。表示太年轻了,规律没找出来,只要a + b < b + a  排序就好了。




//第一题 #include #include #include #include using namespace std; typedef long long ll; const int maxn = 50; int n, p; char a[10] = {'half'}; char b[10]; int tmp[maxn]; void init(){ memset(tmp, 0, sizeof(tmp)); for (int i = n - 1; i >= 0; i--){ memset(b, 0, sizeof(b)); scanf("%s", b); //printf("len = %d\n", strlen(b)); if (strlen(b) == 4) tmp[i] = 1; else tmp[i] = 0; } //for (int i = 0; i < n; i++) printf("tmp = %d\n", tmp[i]); } void solve(){ ll cnt = 0, res = 0; for (int i = 0; i < n; i ++){ //if (i == 0) {cnt = 1; continue;} if (tmp[i] == 0){ res += cnt * p; res += p / 2; cnt = cnt * 2 + 1; } else { res += cnt * p; cnt = 2 * cnt; } } printf("%I64d\n", res); } int main(){ while (scanf("%d%d", &n, &p) == 2){ init(); solve(); } return 0; } //第二题 #include #include #include using namespace std; typedef long long ll; const int maxn = 500000 + 10; int n; ll sum; ll p[maxn]; ll sumb[maxn], suma[maxn]; char atlas[maxn]; void init(){ sum = 0; for (int i = 0; i < n; i++){ scanf("%I64d", p + i); } memset(suma, 0, sizeof(suma)); memset(sumb, 0, sizeof(sumb)); scanf("%s", atlas); for (int i = 0; i < n; i++){ if (i == 0){ if (atlas[i] == 'A') suma[i] = p[i]; else sumb[i] = p[i]; } else if (atlas[i] == 'A'){ suma[i] = suma[i - 1] + p[i]; sumb[i] = sumb[i - 1]; } else if(atlas[i] == 'B'){ suma[i] = suma[i - 1]; sumb[i] = sumb[i - 1] + p[i]; } if (atlas[i] == 'B') sum += p[i]; } } void solve(){ ll res = 0; for (int i = 0; i < n; i++){ res = max(res, sum - sumb[i] + suma[i]); res = max(res, sum - sumb[n - 1] + sumb[i] + suma[n - 1] - suma[i]); } printf("%I64d\n", res); } int main(){ while (scanf("%d", &n) == 1){ init(); solve(); } return 0; } //第三题 #include #include #include #include using namespace std; const int maxn = 50000 + 50; const int maxa = 50 + 5; int n; string atlas[maxn]; char a[maxn]; char t[maxn]; void init(){ for (int i = 0; i < n; i++){ scanf("%s", t); atlas[i] = string(t); } } bool cmp(const string &a, const string &b){ return (a + b) < (b + a); } void solve(){ sort(atlas, atlas + n, cmp); int cnt = 0; for (int i = 0; i < n; i++){ for (int j = 0; j < (int)atlas[i].size(); j++){ a[cnt++] = atlas[i][j]; } } printf("%s\n", a); } int main(){ while (scanf("%d", &n) == 1){ init(); solve(); } return 0; } //其实还可以再短一点 #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; typedef long double ld; using namespace std; string s[60000]; bool cmp(const string& a, const string& b) { return (a + b) < (b + a); } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> s[i]; sort(s, s + n, cmp); for (int i = 0; i < n; ++i) cout << s[i]; cout << "\n"; return 0; }

你可能感兴趣的:(CF,数学)