Codeforces Round #346 (Div. 2) A Round-House
A. Round House
题目链接http://codeforces.com/contest/659/problem/A
Description
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.
Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.
Input
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.
Output
Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.
Sample Input
6 2 -5
Sample Output
3
题意:
给你一个环,你一开始在a位置,然后你走b步,求走完后地址。
题解:
先将最环节全部去掉,剩下绝对值在a以内的数。这样就可以通过环的性质求出数据。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1123456789;
int s[1000];
int main()
{
int key = 0;
int n,a,b;
cin>>n>>a>>b;
if (b >= 0){
if ((a+b)%n == 0)
cout<<n<<endl;
else cout<<((a+b)%n)<<endl;;
}else {
int sb = b;
while (sb < 0){
sb+=n;
}
if ((a+sb)%n == 0)
cout<<n<<endl;
else cout<<((a+sb)%n)<<endl;;
}
return 0;
}
Codeforces Round #346 (Div. 2) A Round-House的更多相关文章
- Codeforces Round #346 (Div. 2) A. Round House 水题
A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...
- Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)
Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...
- Codeforces Round #346 (Div. 2) A题 [一道让我生气的思维题·]
A. Round House Vasya lives in a round building, whose entrances are numbered sequentially by integer ...
- Codeforces Round #346 (Div. 2) D Bicycle Race
D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...
- Codeforces Round #346 (Div. 2) C Tanya and Toys
C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...
- Codeforces Round #346 (Div. 2) B Qualifying Contest
B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...
- Codeforces Round #346 (Div. 2) G. Fence Divercity dp
G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...
- Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集 bfs
F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Pol ...
- Codeforces Round #346 (Div. 2) E. New Reform dfs
E. New Reform 题目连接: http://www.codeforces.com/contest/659/problem/E Description Berland has n cities ...
随机推荐
- elasticsearch data importing
ElasticSearch stores each piece of data in a document. That's what I need. Using the bulk API. Trans ...
- Citrix 服务器虚拟化之四 Xenserver资源池
Citrix 服务器虚拟化之四 Xenserver资源池 台主机,尽管这种限制没有执行.池总是至少有一个物理节点,称为主.只有主节点公开管理界面(使用XenCenter和XenServer命令行界面 ...
- Operation not permitted引发的惊魂72小时
0.问题及描述 在测试产品的时候,莫名其妙发现了我们的主进程VPNd会出现以下的报错: 2013-07-18 13:05:13 www.1.com/192.168.200.220:65527 wri ...
- mpi和cuda混合编程的正确编译
针对大数据的计算,很多程序通过搭建mpi集群进行加速,并取得了很好的效果.算法内部的加速,当前的并行化趋势是利用GPU显卡进行算法加速.针对并行性非常好的算法,GPU加速效果将远大于集群带来的加速效果 ...
- .NET基础——ASSCII码表
char类型不能直接强转为int32,因为强转后的结果是去ascii码表的值.如char 类型的1,强转为int32后的值是49. 要得到正确的结果,现将char类型转换为string类型,再转为in ...
- mysql建立、删除索引及使用
同步发布:http://www.yuanrengu.com/index.php/2017-01-13.html 一.索引的作用 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少 ...
- jboss服务启动失败报:Error occurred during initialization of VM
今天下午突然间公司的GTV管理平台上不去了 访问确实,提示找不到页面 登录终端查看服务进程. ps -ef | grep jboss 发现没有这个进程.怎么办,启动被. 输入nohup /home/c ...
- 图片,音频资源预加载和文档dom加载
在项目中遇到一个问题,ajax请求音频资源,然后动态的插入到文档中,其中.原生的音频外观实在太丑了,而且每个浏览器的样式都不一样,采取了一个audio插件. 就遇到一个问题,请求后的直接调用插件的话, ...
- hdu 5997 rausen loves cakes(线段数合并+启发式修改)
题目链接:hdu 5997 rausen loves cakes 题意: 给你n个点,每个点有一个颜色,现在有两个操作,第一个操作,将颜色x改为颜色y,第二个操作,询问[x,y]区间有多少颜色段(颜色 ...
- js中substr,substring,indexOf,lastIndexOf等的用法
1.substrsubstr(start,length)表示从start位置开始,截取length长度的字符串. var src="images/off_1.png";alert( ...