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)
考察能否通过一次翻转,将数组变为升序。其实就是考虑第一个下降的位置,和之后第一个上升的位置,判断边界值大小,细心的话很容易发现。不过这道题坑点好多,虽然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;
}