B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
1 second
256 megabytes
standard input
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).
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.
求选哪个点使得|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) 简单题)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- 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 ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- 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 ...
- 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了. 总结:下次一定要注意了,提交前一定要看 ...
- Codeforces Round #316 (Div. 2B) 570B Simple Game 贪心
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...
随机推荐
- CSS浮动(Float)
定义 浮动会使元素向左或向右移动,其周围的元素也会重新排列: 浮动直到它的外边缘碰到包含框或者另一个浮动框才停止: 浮动之后的元素将围绕它,浮动之前的元素不变: 由于浮动框不在文档的普通流中,所以文档 ...
- Python爬虫入门:Urllib库的基本使用
1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由浏览器解释才呈现出来的,实质它 是一段HTML代码,加 JS.CS ...
- iOS 极光推送的集成以及一些集成后的狗血
1.首先进入极光文档下载激光推送的SDk---传送门http://docs.jiguang.cn/jpush/client/iOS/ios_sdk/ 将解压后的lib子文件夹(包含JPUSHSer ...
- DbContext 中的 Explicit interface implementation
疑惑 前段时间一直再用Entity Framework 6,写了一些公用的方法,在这个过程中发现了DbContext实现的接口IObjectContextAdapter,可以通过这个接口访问到更底层的 ...
- JSTL中foreach与fn表达式
在jstl中的fn标签也是我们在网页设计中经常要用到的很关键的标签,在使用的时候要先加上头 <%@ taglib uri=" http://java.sun.com/jsp/jstl/ ...
- Spring配置补充
# :Spring配置补充 ## 一:灵活配置DataSource (1) 使用属性文件配置数据源 (2) 使用JNDI数据源 (3) Spring中的Bean的作用域问题, Sin ...
- [转载] 使用HTML5的十大原因
转载自http://www.williamlong.info/archives/3024.html 你难道还没有考虑使用HTML5? 当然我猜想你可能有自己的原因:它现在还没有被广泛的支持,在IE中不 ...
- PHP Xdebug安装及配置
1.首先在官方网站下载dll文件; Xdebug官方网站 2.将php_xdebug.dll文件放入php/ext文件夹下; 3.编辑php.ini,在文件最后加入如下代码: ; Xdebug zen ...
- Unity3D高性能战争迷雾实现
效果图 先上效果图吧,这是为了吸引到你们的ヽ(。◕‿◕。)ノ゚ 战争迷雾效果演示图 战争调试界面演示图 由于是gif录制,为了压缩图片,帧率有点低,实际运行时,参数调整好是不会像这样一卡一顿的. 战争 ...
- Swarm 如何实现 Failover?- 每天5分钟玩转 Docker 容器技术(98)
故障是在所难免的,容器可能崩溃,Docker Host 可能宕机,不过幸运的是,Swarm 已经内置了 failover 策略. 创建 service 的时候,我们没有告诉 swarm 发生故障时该如 ...