B - Simple Game

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 Input

Input
3 1
Output
2
Input
4 3
Output
2

这道题没有涉及什么算法问题,题意就是Misha和Andrew宝宝玩猜数字游戏,总共有n(1~n)个数字,Misha给出的数字记为m,Andrew给出的数字记为a,随机取(1~n)中的一个数,所取数值距此数最近的人获胜。现已知m和n,问a给多少才能使Andrew获胜的几率最大。(如果有两个或多个点获胜的几率都是最大,取数值最小的点)对了,如果两个人距离相等则Misha胜,毕竟女孩子~

先找出n个数的中点,看m在哪边,先分点的个数是奇是偶,再判断m是否在中点上,分别判断。

比较朴素的思路,AC代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,m,mid,ans;
scanf("%d %d",&n,&m);
if(n%==) {//n为偶数时点的个数为偶数,中点分为两个,当m取任意一个时,a取另一个
mid=n/;
if(m<=mid) ans=m+;
else ans=m-;
}
else {
mid=n/+; //n/2取较小的整数值
if(m<mid) ans=m+;
else ans=m-;
}
if(ans==) ans=;
printf("%d\n",ans);
return ;
}

B - Simple Game的更多相关文章

  1. PHP设计模式(一)简单工厂模式 (Simple Factory For PHP)

    最近天气变化无常,身为程序猿的寡人!~终究难耐天气的挑战,病倒了,果然,程序猿还需多保养自己的身体,有句话这么说:一生只有两件事能报复你:不够努力的辜负和过度消耗身体的后患.话不多说,开始吧. 一.什 ...

  2. Design Patterns Simplified - Part 3 (Simple Factory)【设计模式简述--第三部分(简单工厂)】

    原文链接:http://www.c-sharpcorner.com/UploadFile/19b1bd/design-patterns-simplified-part3-factory/ Design ...

  3. WATERHAMMER: A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION

    开启阅读模式 WATERHAMMER A COMPLEX PHENOMENON WITH A SIMPLE SOLUTION Waterhammer is an impact load that is ...

  4. BZOJ 3489: A simple rmq problem

    3489: A simple rmq problem Time Limit: 40 Sec  Memory Limit: 600 MBSubmit: 1594  Solved: 520[Submit] ...

  5. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. 设计模式之简单工厂模式Simple Factory(四创建型)

    工厂模式简介. 工厂模式专门负责将大量有共同接口的类实例化 工厂模式可以动态决定将哪一个类实例化,不必事先知道每次要实例化哪一个类. 工厂模式有三种形态: 1.简单工厂模式Simple Factory ...

  8. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  9. 关于The C compiler "arm-none-eabi-gcc" is not able to compile a simple test program. 的错误自省...

    在 GCC ARM Embedded https://launchpad.net/gcc-arm-embedded/ 上面下载了个arm-none-eabi-gcc 用cmake 编译时 #指定C交叉 ...

  10. A Simple OpenGL Shader Example II

    A Simple OpenGL Shader Example II eryar@163.com Abstract. The OpenGL Shading Language syntax comes f ...

随机推荐

  1. NERO8.0刻录系统光盘

    正常启动NREO,点击NERO 8.0左下角图标(启动NERO应用程序和工具),选NERO Express Essentials,在左边的几个选项中选择“映像.项目.复制”,右边选“光盘映像或保存的项 ...

  2. PHP CURL 中文说明

    1.CURL是利用URL语法在命令行方式下工作的开源文件传输工具. 2.它被广泛应用在Unix.多种Linux发行版中.而且有DOS和Win32.Win64下的移植版本号. 3.它支持非常多协议:FT ...

  3. webstorm-----eslint的配置和使用

    https://blog.csdn.net/qq_29329037/article/details/80100450

  4. Linux 命令汇总总结相关

    玩了linux快一年,简单总结下网络相关的命令,具体每个命令的参数可以用到再细看. 1.ifconfig:查询.设置网卡和IP网段等相关参数,包括MTU.2.ifup.ifdown:这两个命令就是一个 ...

  5. EasyPlayer Android安卓RTSP服务器低延时再优化策略

    EasyPlayer低延迟再优化策略 EasyPlayer是一款专门针对RTSP协议进行过优化的播放器.其中两个我们引以为傲的的优点就是起播快和低延迟.最近我们遇到一些需求,其对延迟要求非常苛刻,于是 ...

  6. EasyDSS高性能流媒体服务器前端重构(六)- webpack-dev-server 支持手机端访问

    很多时候,前端开发的页面,不仅要在PC端测试效果, 还要在手机端测试效果. 在开发阶段, 我们以 webpack-dev-server 来启动浏览器, 打开正在开发的页面. webpack-dev-s ...

  7. git merge的本质

    1 git merge [branch] 将[branch]这个分支merge到当前分支. 2 merge的本质 merge就是把branch上的提交合入当前分支的提交树,这两个分支上的所有提交的历史 ...

  8. 【题解】quake

    [题解]\(quake\) 题目大意 我们共有报酬\(f\)元,一条边有它的价值\(w_i\),有它的建造时间\(t_i\).要求建一些边,生成一颗树.求最大的利润率. 数据范围 \(n\le 400 ...

  9. Appium 1.9.1 启动报错 Fatal TypeError: Class constructor BaseDriver cannot be invoked without 'new'

    安装了appium 1.9.1后一直报错Fatal TypeError: Class constructor BaseDriver cannot be invoked without 'new',无法 ...

  10. Linux下/usr/bin/python被删除的后果

    可能部分的人使用linux都有直接root登陆的习惯,这有很大的便利性,因为很多的命令不需要使用sudo请求root权限.但是使用root权限,所有的命令都会立即被执行,即使这个命令是对系统有害处的. ...