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

来源:互联网 发布:美工怎么上传 编辑:程序博客网 时间:2024/06/03 16:00

题目链接: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;}
0 0
原创粉丝点击