您的位置:首页 > 其它

570B. Simple Game Codeforces Round #316 (Div. 2)

2015-08-14 09:39 351 查看
题目链接:Click here

题意:Misha 和 Andrew 要玩一个游戏,从1~n中两人分别选一个数,然后随机选择一个数c,如果Misha 选的数与c的距离小于或等于Andrew 选的数与c的距离,Misha 赢,否则Andrew 赢。

这道题比赛时被HACK了,想了好久感觉没问题了,最后试了下1 1, 果然输出为0,不对了。。但答案是1也不对啊,这种情况Andrew 不可能赢啊 :(

思路简单,具体看代码吧

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
int m, n, ans;
while(scanf("%d%d", &m, &n) != EOF)
{
if(m % 2 == 0)
{
if((m - n) >= n)
ans = n + 1;
else
ans = n - 1;
}
else
{
if((m - n) > n)
ans = n + 1;
else
ans = n - 1;
}
if(m == 1) printf("1\n");
else
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: