CodeForces 659A Round House

来源:互联网 发布:node.js 编译 编辑:程序博客网 时间:2024/06/07 07:34
L - L
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status

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.

Illustration for n = 6a = 2b =  - 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 na 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

Input
6 2 -5
Output
3
Input
5 1 3
Output
4
Input
3 2 7
Output
3
题意:给你一个环,给出起点和步数(正负方向不同),问能走到哪。
思路:模拟一遍就可以了。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){int num[210],n,a,b,m,i,j;while(scanf("%d%d%d",&n,&a,&b)!=EOF){for(i=1;i<=n;i++)num[i]=i;for(i=n+1;i<=2*n;i++)//这是一个比较机智的地方。 num[i]=i-n;if(b<0){b=-b;b=b%n;b=n-b;}    else    {    b=b%n;}printf("%d\n",num[a+b]);}return 0;}


0 0
原创粉丝点击