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

贪心,如果m分成的两个区间长度不相等,那么选长的那个区间最接近m的位置,否则选m-1位置,特判一下n等于1的情况

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n == 1){
        printf("1"); return 0;
    }
    int d1 = m-1, d2 = n-m;
    if(d1<d2){
        printf("%d",m+1);
    }else {
        printf("%d",m-1);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/jerryRey/p/4728870.html