Codeforces Round #258 (Div. 2) summary,
A. Game With Sticks (451A)
In fact, no matter which intersection you choose, the result is that the number of rows and columns are reduced by one. Now, whoever first reduces the number of rows and the number of columns is 0, wins. Because Akshat is selected first, if the smallest of the columns is an odd number, Akshat wins. Otherwise, Malvika wins.
Code:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int a, b; while(~scanf("%d%d", &a, &b)) { int minn = a>b?b:a; if(minn%2==0) printf("Malvika\n"); else printf("Akshat\n"); } return 0;}
B. 451B-Sort the Array (451B)
Whether the array can be changed to ascending order by one flip. In fact, it is easy to find out the first drop position, the first rising position, and the boundary value. However, this question has many pitfalls. Although Pretest Pass is passed, WA is finished at last, because there is a condition in output that is not considered (start must not be greater than end ). As a result, it is difficult to write less judgment conditions.
Code:
By dzk_acmer, contest: Codeforces Round #258 (Div. 2), problem: (B) Sort the Array, Accepted, # #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n, a[100010]; while(~scanf("%d", &n)) { for(int i = 1; i <= n; i++) scanf("%d", &a[i]); if(n == 1) { printf("yes\n1 1\n"); continue; } if(n == 2) { printf("yes\n"); if(a[1] < a[2]) printf("1 1\n"); else printf("1 2\n"); continue; } int st = 1, ed = n, up = 0, down = 0; for(int i = 2; i < n; i++) { if(a[i] > a[i-1] && a[i] > a[i+1]) { up++; st = i; } if(a[i] < a[i-1] && a[i] < a[i+1]) { down++; ed = i; } } a[0] = -100; a[n+1] = 1e9+2; if(up >= 2 || down >= 2 || st >= ed || a[st] > a[ed+1] || a[ed] < a[st-1]) { printf("no\n"); continue; } printf("yes\n"); if(a[st] > a[ed]) printf("%d %d\n", st, ed); else printf("1 1\n"); } return 0;}