codeforces 570B Simple Game

标签: codeforces
1人阅读 评论(0) 收藏 举报
分类:

点击打开链接

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.

Examples
input
Copy
3 1
output
Copy
2
input
Copy
4 3
output
Copy
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.


这个题不难理解,但是就是做不出来,都要百度看别人的代码了,他们给的分类是思维题,然后就没看,我想自己做。

注意几组数据

5 5

输出 4

1 1

输出

1


#include<bits/stdc++.h>  
using namespace std;  
typedef long long ll;  
const int inf = 0x3f3f3f3f;  
int main()   
{  
    // freopen("shuju.txt","r",stdin);
    int n,m;
    cin>>n>>m;
    int dis1=m,dis2=n-m+1;
    if(n==1&&m==1)
        cout<<"1"<<endl;
    else if(n==m)
        cout<<n-1<<endl;
    else
    {
        if(dis1<dis2)
            cout<<m+1<<endl;
        else
            cout<<m-1<<endl;
    }
    return 0;  
}




查看评论

Codeforces 570B Simple Game 概率求解,简单数学思维

题目描述了这么一个情景,给定一个范围 1~n ,两个人(简记为 a和b)各自随机选一个整数,然后再在1~n这个范围内随机找一个整数(1~n所有整数被选到的概率是相等的),这两个人谁选择的数更接近这个随...
  • skyword_sun
  • skyword_sun
  • 2015-08-14 09:49:39
  • 719

Codeforces 570B Simple Game【思维】

B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input st...
  • mengxiang000000
  • mengxiang000000
  • 2017-01-10 17:04:40
  • 168

Codeforces 570B Simple Game

题目链接: http://codeforces.com/problemset/problem/570/B 解题思路: Lets find which variant is interesting...
  • piaocoder
  • piaocoder
  • 2015-08-14 08:52:52
  • 350

CodeForces 570B Simple Game

#include//要想概率大就挨着放 int main(){ int n,m,ans; scanf("%d%d",&n,&m); if(n==1) {ans=1;printf...
  • Hzy_hzy_hzy
  • Hzy_hzy_hzy
  • 2016-07-13 09:48:41
  • 162

CodeForces - 570B Simple Game

题意分析 给出n,m 求一个数a(1&amp;lt;=a&amp;lt;=n)使得当c在1到n的整数中随机取值时,|c-a|&amp;lt;|c-m| 成立的概率最大。 想一下绝对值函数的图像,然...
  • pengwill97
  • pengwill97
  • 2018-03-07 21:56:13
  • 39

Codeforces 570B

题意:有A和B玩游戏,从1~n数字里,A选了m,B选了a,假设有一个数字c在1~n中,如果m离c更近或者m和a与c的距离是相等的,都是A胜,已知n和m,问a取多少可以让B的胜率最大。 题解:贪心,如...
  • u013392752
  • u013392752
  • 2015-08-15 00:02:54
  • 469

【CodeForces 570B】Simple Game(水)

 Simple Game One day Misha and Andrew were playing a very simple game. First, each player choose...
  • fsmm_blog
  • fsmm_blog
  • 2017-03-10 20:58:22
  • 80

CodeForces 570B Simple Game 概率

原题: http://codeforces.com/contest/570/problem/B题目大意: 知道总共可以选的数,和misha选的数,求andrew选一个能让尽可能多的数到andrew...
  • qq_27508477
  • qq_27508477
  • 2015-08-14 10:19:49
  • 569

Codeforces-513A-Game

Two players play a simple game. Each player is provided with a box with balls. First player’s box co...
  • Ypopstar
  • Ypopstar
  • 2016-09-11 17:40:37
  • 310

cf 570B Simple Game 水题

链接:点击打开链接 B. Simple Game time limit per test 1 second memory limit per test 256...
  • migu77777
  • migu77777
  • 2016-09-04 23:04:36
  • 129
    new-新东西
    这个博客写的好多都是算法,现在有了新的博客,有些东西会发布在这个。。。。。。。。。。。。 访问我的新博客
    个人资料
    持之以恒
    等级:
    访问量: 3万+
    积分: 2352
    排名: 2万+
    最新评论