思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间。a=m+1,假设m在右区间,a=m-1。可是我居然忘了处理1,1这个特殊数据。被人hack了

总结:下次一定要注意了,提交前一定要看下边界数据,不要急着交。

题目链接:http://codeforces.com/problemset/problem/570/B

<pre name="code" class="cpp">#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(void)
{
int a;
scanf("%d%d",&n,&m);
if(n==1&&m==1)//处理1,1
{
printf("1\n");
}
else
{
if(n&1)
{
if(m==n/2+1) a=n/2;//假设n是奇数,恰巧m是最中间那个数,由于要取最小,所以取左边的数
else if(m<n/2+1) a=m+1;
else a=m-1;
}
else
{
if(m>n/2) a=m-1;
else a=m+1;
}
printf("%d\n",a);
}
return 0;
}


Codeforces Round #316 (Div. 2) B. Simple Game的更多相关文章

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

    题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...

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

    贪心,如果m分成的两个区间长度不相等,那么选长的那个区间最接近m的位置,否则选m-1位置,特判一下n等于1的情况 #include<bits/stdc++.h> using namespa ...

  3. B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)

    B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Codeforces Round #316 (Div. 2) C. Replacement set

    C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...

  5. Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树

    C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...

  6. Codeforces Round #316 (Div. 2)

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

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

    B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #316 (Div. 2) (ABC题)

    A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...

  9. Codeforces Round #316 (Div. 2) C. Replacement

    题意:给定一个字符串,里面有各种小写字母和' . ' ,无论是什么字母,都是一样的,假设遇到' . . ' ,就要合并成一个' .',有m个询问,每次都在字符串某个位置上将原来的字符改成题目给的字符, ...

随机推荐

  1. 封装cookie的获取,设置与查找

    //获取cookiefunction getCookie(key,value){ var c = document.cookie; var str = key + '=' + value; var r ...

  2. root of factory hierarchy

    项目编译错误! project---->clean

  3. yum下载的rpm包离线安装

    #修改yum设置,让rpm包缓存到本地 vi /etc/yum.conf #修改keepcache为1 keepcache=1 #清空yum缓存 yum clean all #安装你要离线安装的rpm ...

  4. 【Henu ACM Round#24 A】k-String

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果是一个k-string的话. 考虑最后的串假设形式为sss..ss(k个s) 则s中出现的字母,整个串中最后出现的次数肯定为k的 ...

  5. 洛谷—— P2896 [USACO08FEB]一起吃饭Eating Together

    https://www.luogu.org/problem/show?pid=2896 题目描述 The cows are so very silly about their dinner partn ...

  6. COGS——T 1578. 次小生成树初级练习题

    http://www.cogs.pro/cogs/problem/problem.php?pid=1578 ☆   输入文件:mst2.in   输出文件:mst2.out   简单对比时间限制:1 ...

  7. [MST] Loading Data from the Server using lifecycle hook

    Let's stop hardcoding our initial state and fetch it from the server instead. In this lesson you wil ...

  8. ural 1143. Electric Path(凸包上最短哈密顿路径)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1143 题意:逆时针给一个凸包的n(n<=200)个顶点坐标,求一个最短哈密顿路径的 ...

  9. 是时候学一波STL了。。。

    都到如今了还不会STL,赶紧学习一下. .. 头文件#include<algorithm> 加上 using namespace std. 求下一个排列的函数:next_permutati ...

  10. sass09

    scss /* 1.使用自定义function和@each实现栅格布局. @function buildLayout($num: 5){ } 结果: col1{width: 20%} col2{wid ...