(Codeforce)The number of positions
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers n, a and b (0≤a,b<n≤100).
Print the single number − the number of the sought positions.
3 1 1
2
5 2 3
3
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5.
简单翻译就是排队,三个输入,一个是队伍的人数n,一个是在排在他前面不能少于a的人,另一个是排在他后面不多于b的人
输出: 他可以站的位置。
可以看第一个case input 3 1 1 他可以站2 他前面有1个人后面1个人 他可以站3 前面2个人后面没有人
idea :
1.当a>=n,则肯定没有位置供选择 则输出0
2.当a+b==n时,我们可以发现我们所能选的就是从a开始到n结束 即b个位置
3.当a+b<n时,我们可以从n-b开始到n 考虑端点就是b+1个嘛
4.当a+b>n时 且a<n,我们可以从a+1开始取,取到n,就是n-a个位置
AC:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n,a,b;
cin >> n >> a >> b;
if(a+b==n)
{
cout << b;
}
else if(a+b<n)
{
cout << b+;
}
else if(a>=n)
{
cout << ;
}
else
{
cout << n-a;
} }
(Codeforce)The number of positions的更多相关文章
- (转载)Flash Number 数据类型
(转载)http://www.g168.net/txt/flash/learningactionscript/00001183.html Number 数据类型 Number 数据类型是双精度浮点数. ...
- java基础系列(一):Number,Character和String类及操作
这篇文章总结了Java中最基础的类以及常用的方法,主要有:Number,Character,String. 1.Number类 在实际开发的过程中,常常会用到需要使用对象而不是内置的数据类型的情形.所 ...
- LeetCode之旅(18)-Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defi ...
- LeetCode(137) Single Number II
题目 Given an array of integers, every element appears three times except for one. Find that single on ...
- LeetCode(202) Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defi ...
- LeetCode之旅(17)-Ugly Number
题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive num ...
- LeetCode(306) Additive Number
题目 Additive number is a string whose digits can form additive sequence. A valid additive sequence sh ...
- LeetCode(65) Valid Number
题目 Validate if a given string is numeric. Some examples: "0" => true " 0.1 " ...
- (Codeforce)Correct Solution?
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and g ...
随机推荐
- (未完)经典Web漏洞实战演练靶场笔记
记录下自己写的经典Web漏洞靶场的write up,包括了大部分的经典Web漏洞实战场景,做个笔记. 0x01 任意文件下载漏洞 if(!empty($_GET['filename'])){ $fil ...
- 超级好用的 Java 数据可视化库:Tablesaw
本文适合刚学习完 Java 语言基础的人群,跟着本文可了解和使用 Tablesaw 项目.示例均在 Windows 操作系统下演示 本文作者:HelloGitHub-秦人 HelloGitHub 推出 ...
- SpringBoot:1.开启SpringBoot之旅
什么是 Spring Boot Spring Boot是Spring团队设计用来简化Spring应用的搭建和开发过程的框架.该框架对第三方库进行了简单的默认配置,通过Spring Boot构建的应用程 ...
- qt实现串口通讯
摘要:上位机软件程序通过QT实现,采集输入信息,根据实际需要做出合适的串口通讯协议,实现效果如下图所示: 主要实现的功能: 1.串口基本参数可选,可调 2.显示区域可选择十六进制/asicii码显示, ...
- css布局两端固定中间自适应
第一种:采用浮动 1.1首先来看一下网上一个哥们给的代码 <body> <div class="left">左</div> <div cl ...
- jhipster入门
环境: 阿里云linux /////////////////////////////////////////////////////////////////////yum install java-1 ...
- Swagger -- 解决日期不正确
继 Swagger--解决日期格式显示为Unix时间戳格式 UTC格式 这篇博客解决的日期格式后又发现了一个问题 问题 查询出来的时间没有注意到足足少了8个小时,如图 解决 其实这个问题不是Swag ...
- 关于C#界面开发winform与SharpGL结合鼠标只在OpenGLControl绘图区域显示坐标移动消息响应(鼠标单独在某个控件上的消息响应)
原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/11773260.html 因为很多时候我们开发画图之类的工具时,鼠标移动之类的,都只想在绘图区域 ...
- 包管理工具-yum
yum介绍 yum(全称为 Yellow dog Updater, Modified)是一个在 Fedora和 RedHat 以及 CentOS 中的 Shell 前端软件包管理器.基于 RPM 包管 ...
- 拨云见日,彻底弄清楚Java日志框架 log4j, logback, slf4j的区别与联系
log4j 以及 logback, slf4j 官网 日志框架的困惑 作为一个正常的项目,是必须有日志框架的存在的,没有日志,很难追踪一些奇奇怪怪的系统问题. 但是,我们经常在项目的依赖中,见到奇奇怪 ...