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 ...
随机推荐
- 迷你MVVM框架 avalonjs 0.85发布
迷你MVVM框架 avalonjs 0.85发布 本版本对循环绑定做了巨大改进,感谢@soom, @limodou, @ztz, @Gaubee 提供的大量测试文件. fix scanNodes, 在 ...
- linux nVidia driver 304 319 . installation by hand
It's so painful to install nVidia driver by hand on linux. If you remove it or you want to upgrade b ...
- 34. LotusScript中的错误处理程序
错误处理程序是所有严肃的程序的必要部分.但是在Lotus Notes开发中,很多程序员编写LotusScript代码时,并没有写专门的错误处理代码的习惯.这能够行得通,主要是因为LotusScript ...
- 简单讨论一下 jQuery 事件
事件是 Web 应用中不可或缺的一个东西,用户在应用中执行一个操作的时候,比如鼠标单击时要触发执行一些事情,就可以给该事件绑定一个事件处理程序(event handler).使用 jQuery 的 . ...
- BZOJ1013 [JSOI2008]球形空间产生器sphere(高斯消元)
1013: [JSOI2008]球形空间产生器sphere Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4846 Solved: 2525[Subm ...
- scapy流量嗅探简单使用
官方文档:http://scrapy-chs.readthedocs.io/zh_CN/latest/index.html 参考链接:http://blog.csdn.net/Jeanphorn/ar ...
- Sipdroid实现SIP(五): 用Java实现的UserAgent
I. 概述 UserAgent是SIP协议中的一个概念, 将"打电话"功能中的主叫和被叫逻辑上封装成UserAgent, 就像将"注册"功能的发起方和接收方封装 ...
- 【锋利的Jquery】读书笔记六
ajax优点缺点 json格式的严格 { "people": [ { "firstName": "Brett", "lastNam ...
- FZU 2088 最长队名
Problem 2088 最长队名 Problem Description Jack所在的班级决定组团报名参加FZU校赛.为了体现班级的团结和睦,班长决定用班级所有人的名字连起来组成一个史上最长最醒 ...
- [MFC] 对话框菜单项Menu选中打勾(单选,多选)
近期需要实现一个功能:MFC对话框中,一项菜单下有五个菜单项,改变菜单项选中状态,每次只能选择其中一个打勾.(单选) 然后在网上搜了下资料,稍微总结下,以防后面用到. 1.单选实现: CMenu* m ...