B. Simple Game-----(Codeforces Round #316 (Div. 2))
来源:互联网 发布:淘宝上好的外贸店 编辑:程序博客网 时间:2024/06/05 16:43
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).
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.
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.
3 1
2
4 3
2
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.
分析:水,不多说,hack点为1 1.
CODE:
#include <bits/stdc++.h>using namespace std;int main(){ int n,m; while(cin>>n>>m){ if(m==1&&n==1){ cout<<1<<endl; continue; } if(n/2<m) cout<<m-1<<endl; else cout<<m+1<<endl; } return 0;}
- Codeforces Round #316 (Div. 2) B. Simple Game (模拟)
- B. Simple Game-----(Codeforces Round #316 (Div. 2))
- Codeforces Round #316 (Div. 2)570B Simple Game(脑洞)
- Codeforces Round #316 (Div. 2) -B-Simple Game-水题
- 570B. Simple Game Codeforces Round #316 (Div. 2)
- Codeforces Round #316 (Div. 2) B. Simple Game
- Codeforces Round #316 (Div. 2) B. Simple Game
- Codeforces Round #316 (Div. 2) B. Simple Game
- Codeforces Round #316 (Div. 2) B. Simple Game
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
- Codeforces Round #357 (Div. 2) B. Economy Game (暴力)
- Codeforces Round #357 (Div. 2) B Economy Game(水题)
- Codeforces Round #200 (Div. 2)B. Simple Molecules
- Codeforces Round #128 (Div. 2) B. Game on Paper
- Codeforces Round #245 (Div. 2) B - Balls Game
- Codeforces Round #263 (Div. 2)B. Appleman and Card Game
- Codeforces Round #263 (Div. 2)B. Appleman and Card Game
- Codeforces Round #263 (Div. 2)-B. Appleman and Card Game
- 二进制整数的乘除运算
- Windows环境下安装Redis
- iOS关闭UITableView中cell的点击事件
- Android训练课程(Android Training) - 高效的显示图片
- 《将博客搬至CSDN》
- B. Simple Game-----(Codeforces Round #316 (Div. 2))
- 使用NDK编译mono
- 类成员没有初始化的危害
- HTTP通信中的请求转发和请求重定向
- HDU 5365 Run (简单分析+暴力枚举)
- 前端设计之CSS布局:上中下三栏自适应高度CSS布局
- 网贷系统架构——前端框架的选择
- POJ 3274 Gold Balanced Lineup
- 模拟 - hdu5360 Hiking