(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 ...
随机推荐
- git的下载及简单使用一
git 是世界上最先进的分布式版本控制系统 常用的git网站 GitHub gitee(码云) git的下载地址 https://git-scm.com/downloads 而后根据计算机的系统选择相 ...
- 代码审计之create_function()函数
0x00 create_function()简介 适用范围:PHP 4> = 4.0.1,PHP 5,PHP 7 功能:根据传递的参数创建匿名函数,并为其返回唯一名称. 语法: create_f ...
- msf各种弱口令爆破
Msf: 写的很乱 记录下msf各个爆破弱口令的模块 run post/windows/gather/arp_scanner RHOSTS=10.10.10.0/24 使用arp_scanner模块 ...
- 【RabbitMQ 实战指南】一 过期时间TTL
RabbitMQ 可以对消息和队列设置过期时间(TTL) 1.设置消息的TTL 目前有两种方式可以设置消息的TTL 第一种方式是通过队列属性设置,队列中所有消息都有相同的过期时间 第二种方式是对消息本 ...
- Spring Boot项目中使用Mockito
本文首发于个人网站:Spring Boot项目中使用Mockito Spring Boot可以和大部分流行的测试框架协同工作:通过Spring JUnit创建单元测试:生成测试数据初始化数据库用于测试 ...
- ElasticSearch业务逻辑案例
ElasticSearch业务逻辑案例 一.业务难题 我们有一个索引: myindex/mytype(为了方便,我们下文以a/b表示) 索引类型中的一个字段group之前是a.b.c(历史遗留问题), ...
- Opentracing + Uber Jaeger 全链路灰度调用链,Nepxion Discovery
当网关和服务在实施全链路分布式灰度发布和路由时候,我们需要一款追踪系统来监控网关和服务走的是哪个灰度组,哪个灰度版本,哪个灰度区域,甚至监控从Http Header头部全程传递的灰度规则和路由策略.这 ...
- fenby C语言 P23
#include <stdio.h> int main(){ int i,max,a[5]={10,5,20,31,4}; max=a[0]; for(i=0;i<5;i++) if ...
- BFM模型介绍及可视化实现(C++)
BFM模型介绍及可视化实现(C++) BFM模型基本介绍 Basel Face Model是一个开源的人脸数据库,其基本原理是3DMM,因此其便是在PCA的基础上进行存储的. 目前有两个版本的数据库( ...
- centos7 搭建ftp 并配置用户目录
1.如果是阿里云服务器,登录控制后台,配置规则,开启21端口 (sftp是加密文件传输使用的22端口,我们这几是搭建ftp服务器) 2.安装配置vsftp服务器 一.配置防火墙,开启FTP服务器需要的 ...