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 ...
随机推荐
- linux学习之linux的hostname修改详解《转》
linux的hostname是一个kernel变量,可以通过hostname命令来查看本机的hostname.也可以直接cat /proc/sys/kernel/hostname查看. #hostna ...
- cf 323A A. Black-and-White Cube 立体构造 不知道为什么当k为奇数时构造不出来 挺有趣的题目吧
A. Black-and-White Cube time limit per test 1 second memory limit per test 256 megabytes input stand ...
- All about Performing User-Managed Database Recovery
Automatic Recovery with SET AUTORECOVERY ======================================== Issuing SET AUTORE ...
- php+redis实现多台服务器内网存储session并读取
大型网站由于大并发的问题会导致系统出现诡异的崩溃性问题这着实让人很是蛋疼,首先考虑的就是负载均衡服务器来处理这个,当然数据库的性能也是非常非常重要的,今天就说下在负载均衡情况下对于session这个问 ...
- C语言之字符集、ASCII码和sizeof运算符
一 字符集和ASCII码 结论:字符本质上也是一个整数,每个字符都有唯一一个与之对应的整数, 比如说小写的a对应97,b对应98,c对应99,大写的A对应65,B对应66,C对应67 所以字符对应的那 ...
- Java的常用包
java.lang: 这个包下包含了Java语言的核心类,如String.Math.Sytem和Thread类等,使用这个包无需使用import语句导入,系统会自动导入这个包中的所有类. java. ...
- 线段树练习 3&&P3372 【模板】线段树 1
题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. 输入描述 Input Description 第一行一个正整数n,接下 ...
- 虚拟机学习centos服务器版
虚拟机安装下载教程:http://www.cnblogs.com/CyLee/p/5615322.html centos 6.5下载地址:http://www.centoscn.com/CentosS ...
- LintCode ---- 刷题总结
对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始).如果不存在,则返回 -1. 基本:两重for循 ...
- 第11章 使用PHP从Web访问MySQL数据库
1.过滤用户可能值其搜索条件的起始或结束位置不小心输入的空白字符: 应用trim(): 2.转义数据(第4章)函数:addslashes(),stripslashes(),get_magic_quot ...