Codeforces Round #346 (Div. 2) A. Round House 水题
2016-03-31 17:13
239 查看
A. Round House
题目连接:
http://www.codeforces.com/contest/659/problem/ADescription
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.
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 -5Sample Output
3Hint
题意
给你一个环形轨道,你一开始在a,然后你走b步,问你在哪儿。题解:
这个小心负数的情况,为了避免这个,我直接将a+=100*n,这样就不会有负数的情况了。代码
#include<bits/stdc++.h> using namespace std; int main() { long long n,a,b; cin>>n>>a>>b;a--; a=a+100*n; a=a+b; cout<<a%n+1<<endl; }
相关文章推荐
- 移动端 touchmove高频事件与requestAnimationFrame的结合优化
- JS 中如何判断 undefined 和 null
- 开发环境配置-eclipse中git的安装、配置与使用-4
- 基于jquery实现轮播焦点图插件
- Linux指定动态库路径
- android内存泄露总结
- [ERROR] SSL error: Unable to get private key from 'server-key.pem'
- 【SVN】SVN错误[ locked; try performing 'cleanup']的解决办法
- 相邻兄弟选择器(+)
- 15个数用循环结构比较大小
- svn checkout操作
- 封装继承多态
- Adnroid 面试题 关于AsyncTask源码解析
- AndroidJNI实践(2)--无需头文件的常规办法-JNI动态注册
- 系统Intent集合
- Android系统性能调优工具介绍
- ThinkPHP处理海量数据分表机制详细代码
- Swift&OC混编
- Sea.js
- (转)ON DUPLICATE KEY UPDATE --mysql的一个有趣语法