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. WCP人员管理之添加人员

    1.用户管理页面 其中 : var url_formActionUser = "user/form.do";//增加.修改.查看URL 2. 通过 /form 路由, 转到 Use ...

  2. 【BZOJ4843】[Neerc2016]Expect to Wait 排序

    [BZOJ4843][Neerc2016]Expect to Wait Description ls最近开了一家图书馆,大家听说是ls开的,纷纷过来借书,自然就会出现供不应求的情况, 并且借书的过程类 ...

  3. 【BZOJ3997】[TJOI2015]组合数学 最长反链

    [BZOJ3997][TJOI2015]组合数学 Description 给出一个网格图,其中某些格子有财宝,每次从左上角出发,只能向下或右走.问至少走多少次才能将财宝捡完.此对此问题变形,假设每个格 ...

  4. 浅尝NODE.js

    Node.js是Google公司开发的,安装好必要的环境以后,可以在服务端上跑的js,可以接收和回应http请求,所有方法都支持异步回调,大大提高事务执行效率. 学习地址:http://www.run ...

  5. 转 EBP ESP 的理解

    PS:EBP是当前函数的存取指针,即存储或者读取数时的指针基地址:ESP就是当前函数的栈顶指针.每一次发生函数的调用(主函数调用子函数)时,在被调用函数初始时,都会把当前函数(主函数)的EBP压栈,以 ...

  6. Java for LeetCode 102 Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  7. Maximum Subsequence Sum 【DP】

    Given a sequence of K integers { N​1​​, N​2​​, -, N​K​​ }. A continuous subsequence is defined to be ...

  8. Java多线程系列 基础篇06 synchronized(同步锁)

    转载 http://www.cnblogs.com/paddix/ 作者:liuxiaopeng http://www.infoq.com/cn/articles/java-se-16-synchro ...

  9. Android NDK环境搭建

    本文主要记录NDK环境在Ubuntu下的搭建. 下载NDK 在官网进行下载NDK https://developer.android.com/ndk/downloads/index.html 当前最新 ...

  10. cdcqの省选膜你赛 题解

    题解: 第一题: 有一个很明显的性质:后面的修改不会对前面的询问做出影响,CDQ分治套上BIT即可. 第二题: 有一个类似于斜率的形式,分数规划套上树分治,码量稍大,细节稍多. 最后20W的点出题人原 ...