B. Simple Game
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n.
Let's assume that Misha chose number m, and Andrew chose number a.

Then, by using a random generator they choose a random integer c in the range between 1 and n (any
integer from 1 to n is
chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are
located on the same distance from c, Misha wins.

Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine
which value of a Andrew must choose, so that the probability of his victory is the highest possible.

More formally, you need to find such integer a (1 ≤ a ≤ n),
that the probability that  is
maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).

Input

The first line contains two integers n and m (1 ≤ m ≤ n ≤ 109)
— the range of numbers in the game, and the number selected by Misha respectively.

Output

Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the
minimum of them.

Sample test(s)
input
3 1
output
2
input
4 3
output
2
Note

In the first sample test: Andrew wins if c is equal to 2 or 3.
The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3,
the probability of winning will be 1 / 3. If a = 1,
the probability of winning is 0.

In the second sample test: Andrew wins if c is equal to 1 and 2.
The probability that Andrew wins is 1 / 2. For other choices of a the
probability of winning is less.

求选哪个点使得|c-a| < |c-m|的概率最高





点击打开链接

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<vector>
#include<map> using namespace std; int n,m; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n == 1)
{
printf("1\n");
}
else if(2*m<=n)
{
printf("%d\n",m+1);
}
else
{
printf("%d\n",m-1);
}
}
return 0;
}

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

  1. B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)

    B. Vanya and Books time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)

    B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  4. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  5. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  6. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  7. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

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

    思路:把n分成[1,n/2],[n/2+1,n],假设m在左区间.a=m+1,假设m在右区间,a=m-1.可是我居然忘了处理1,1这个特殊数据.被人hack了. 总结:下次一定要注意了,提交前一定要看 ...

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

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

随机推荐

  1. mongodb集群【】

    参考 http://www.jianshu.com/p/2825a66d6aed http://www.cnblogs.com/huangxincheng/archive/2012/03/07/238 ...

  2. Python+selenium打开网页

    东西都安装好了,是不是都迫不及待的想要运行一个程序呢? 不过不幸的是,在正式编程打开网页之前,我们还需要做一件事:下载驱动. 据说,在很久之前的selenium1和2中,驱动是被内嵌在selenium ...

  3. tornado超时机制

    1.https://blog.lzhaohao.info/archive/build-a-comet-application-using-tornado-and-nginx/ 2.http://qin ...

  4. 【源码解析】Sharding-Jdbc中的算法

    Sharding-jdbc中的很多地方涉及到算法,比如主从配置这块.分库分表这块.本文主要从源码角度介绍下,目前主要包含哪些算法,以及这些算法的内容. 一.读写分离(主从配置) 这块的代码主要在cor ...

  5. 基于 HTML5 WebGL 的 3D “弹力”布局

    分子力(molecular force),又称分子间作用力.范得瓦耳斯力,是指分子间的相互作用.当二分子相距较远时,主要表现为吸引力,这种力主要来源于一个分子被另一个分子随时间迅速变化的电偶极矩所极化 ...

  6. JavaWeb面试(六)

    51.说一说Servlet的生命周期? Servlet有良好的生存期的定义,包括加载和实例化.初始化.处理请求以及服务结束.这个生存期由javax.servlet.Servlet接口的init(),s ...

  7. 0e开头MD5值小结

    s878926199a 0e545993274517709034328855841020 s155964671a 0e342768416822451524974117254469 s214587387 ...

  8. Kaggle初入门

    今天成功的进驻kaggle社区了! 所以以后就要跟kaggle上面的各位一起学习啦! 今天十分成功的在tensorflow的环境里面装了一堆库--什么seaborn啊pandas啊都一次过 然后--并 ...

  9. LSF-SCNN:一种基于 CNN 的短文本表达模型及相似度计算的全新优化模型

    欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 本篇文章是我在读期间,对自然语言处理中的文本相似度问题研究取得的一点小成果.如果你对自然语言处理 (natural language proc ...

  10. windows 下更新 npm 和 node

    原文链接 公司的新项目要启动了,需要使用 Angular 4.0,并且使用 webpack 工具进行打包.所以就需要安装 node.node 的安装很简单,在 node 的官网 nodejs.org  ...