A. Game With Sticks (451A)
水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行、列有一个为0,那么谁就赢了。因为Akshat先选,因此假设行列中最小的一个为奇数,那么Akshat赢,否则Malvika赢。
代码:
#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)
考察是否能通过一次翻转,将数组变为升序。事实上就是考虑第一个下降的位置,和之后第一个上升的位置,推断边界值大小,细心的话非常easy发现。只是这道题坑点好多,尽管Pretest Pass了,可是,最后WA了,由于在output里面有一个条件没有考虑,就是(start
must not be greater than end) 。导致少写一个推断条件,好坑啊。
代码:
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; }
时间: 2024-10-21 14:36:58