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. 【APP问题定位(三)】adb安装

    先来剧透一下我们需要使用的工具 bin包               一个安装目录,可以免安装直接调用adb命令 Android SDK platform tools 下面依次为大家介绍,第1个和第2 ...

  2. table固定头部,表格tbody可上下左右滑动

    当表格头部固定时,需要分为两个表格来做:一部分是thead,一部分是tbody,具体实现方式如下: html代码: <div class="table_box_big"> ...

  3. Android 工程师

    转发:https://zhuanlan.zhihu.com/p/30429725 这句话我真的憋了好久.Android 工程师只要关注我,我就能让你达到大师级水平,不是面试时的吹牛逼水平,不是自我欺骗 ...

  4. Java中swap()实现

    Java中swap()实现 1.今天可爱的谭老师发了一道题目,使用java写方法交换Integer类型数据,而且入参固定了,题目请下图: 入参固定的话,当时想到的是重新定义一个自己的Integer类型 ...

  5. tornado+WSGI+Apache

    1.原理 2.安装mod_wsgi http://pan.baidu.com/s/1sjsccWH configure的时候会找对应的python脚本,默认是/usr/bin/python 生成mod ...

  6. select * from 的一些心得

    如何简单运用好 select * from语句,在不同的函数下,有不同的先后顺序. 语法格式 (代表先后顺便) (2)select 字段名 查询什么东西 (1)from 表名,从哪个表查询 例如:查询 ...

  7. Zabbix服务网页报错汇总

    第1章 Zabbix简介及组成 1.1 zabbix简介 zabbix是一个基于web界面,提供分布式系统监视以及网络监视功能的企业级的开源解决方案.它可以监视各种网络参数,保证服务器自动的安全运营, ...

  8. Python——正则表达式特殊符号及用法

    由于正则表达式的内容比较多,所以单独写成一系列文章,主要内容是根据小甲鱼所讲的内容综合一下正则表达式的笔记. 贴上小甲鱼的<Python3 如何优雅地使用正则表达式>系列可观看的博客地址: ...

  9. 基于MVC设计模式的Web应用框架:struts2的简单搭建(一)

    Struts2的初步介绍 Struts2是apache项目下的一个web 框架,普遍应用于阿里巴巴.京东等互联网.政府.企业门户网站.虽然之前存在了很大的安全漏洞,在2013年让苹果.中国移动.中国联 ...

  10. 2733:判断闰年-poj

    2733:判断闰年 总时间限制:  1000ms 内存限制:  65536kB 描述 判断某年是否是闰年. 输入 输入只有一行,包含一个整数a(0 < a < 3000) 输出 一行,如果 ...