A. Round House
A. Round House
1 second
256 megabytes
standard input
standard output
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance.
Illustration for n = 6, a = 2, b = - 5.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n, - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.
6 2 -5
3
5 1 3
4
3 2 7
3
The first example is illustrated by the picture in the statements.
先分成正负来讨论,然后对n取模,再讨论。
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std; int main()
{
int n,a,b;
scanf("%d%d%d",&n,&a,&b);
if(b>=){
b %= n;
a = (a+b)%n;
if(a == ) printf("%d\n",n);
else printf("%d\n",a);
}
else{
b = abs(b);
b %= n;
if(b<a) printf("%d\n",a-b);
else if(b == a) printf("%d\n",n);
else{
printf("%d\n",n-b+a);
}
}
return ;
}
卷珠帘
A. Round House的更多相关文章
- SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等
在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...
- SQL中Round(),Floor(),Ceiling()函数的浅析
项目中的一个功能模块上用到了标量值函数,函数中又有ceiling()函数的用法,自己找了一些资料,对SQL中这几个函数做一个简单的记录,方便自己学习.有不足之处欢迎拍砖补充 1.round()函数遵循 ...
- oracle的round函数和trunc函数
--Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- mathlab之floor,ceil,round,int以及fix函数
建议自己动手敲敲,网上很多人自己都没搞清楚然后好多错的.毕竟自己亲眼看到结果才有说服力. 以下是我亲眼见到的结果. 1.double floor(double)函数 floor()函数是常用的取整函数 ...
- SQL SERVER四舍五入你除了用ROUND还有其他方法吗?
引言 今天和测试沟通一个百分比计算方式时遇到一个问题, 我在存储过程里用到了强转CAST(32.678 AS DECIMAL(5,1)) 我认为该方式只会保留一位小数,我给测试的回复是我并没有用到四 ...
- JavaScript的几种Math函数,random(),ceil(),round(),floor()
1.Math.random():返回 0 ~ 1 之间的随机数.2.Math.ceil():返回值:返回大于或等于x,并且与之最接近的整数(如果x是正数,则把小数"入":如果x是负 ...
随机推荐
- HDU1272 小希的迷宫 并查集
参考网址:http://blog.sina.com.cn/s/blog_6827ac4a0100nyjy.html 解题思路: 由于这里出现的数字不一定连续的数字都会出现,所以设一个mark来标记数字 ...
- 安装阿里云的php+mysql+nginx+vsftpd
百度云search sh-1.3.0-centos.zip
- 第13章 Swing程序设计----JFrame窗体
JFrame窗体是一个容器,它是Swing程序中各个组件的载体,可以将JFrame看作是承载这些Swing组件的容器. 在开发应用程序时可以通过继承java.swing.JFrame类创建一个窗体,在 ...
- iOS 的 APP 如何适应 iPhone 5s/6/6Plus 三种屏幕的尺寸?
初代iPhone 2007年,初代iPhone发布,屏幕的宽高是 320 x 480 像素.下文也是按照宽度,高度的顺序排列.这个分辨率一直到iPhone 3GS也保持不变. 那时编写iOS的App( ...
- Commit message 和 Change log 编写指南
来源:http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html Git 每次提交代码,都要写 Commit messa ...
- 移植WL18XX到高通的时候,会出现几个.KO文件没有编译出来的情况
1.检查kernel的.config文件,看是否有CONFIG又恢复了.这个时候就要需找依赖.把依赖使能 2.然后再去驱动源码检查 KCONFIG 的依赖,使能改使能的配置就可以了.
- iwlist等工具的移植
http://blog.csdn.net/jk110333/article/details/8658054 参考了这边文章 -------------------------------------- ...
- 【纯欧拉函数】 poj 2407
#include <cstdio> #include <iostream> using namespace std; int phi(int x) { int t=x; ;i& ...
- log4j打印出线程号和方法名
先参考实现配置,如果想要更加详细的配置,可加上更多参数: log4j.rootLogger = INFO,FILE,CONSOLE log4j.appender.FILE.Threshold=INFO ...
- WPF Template模版之DataTemplate与ControlTemplate的关系和应用【二】
1. DataTemplate和ControlTemplate的关系 学习过DataTemplate和ControlTemplate,你应该已经体会到,控件只是数据的行为和载体,是个抽象的概念,至于它 ...