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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #346 (Div. 2) A题 [一道让我生气的思维题·]

    A. Round House Vasya lives in a round building, whose entrances are numbered sequentially by integer ...

  4. Codeforces Round #346 (Div. 2) D Bicycle Race

    D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...

  5. 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 ...

  6. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  7. Codeforces Round #346 (Div. 2) G. Fence Divercity dp

    G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasil ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Citrix 服务器虚拟化之六 Xenserver虚拟机创建与快照

    Citrix 服务器虚拟化之六  Xenserver虚拟机创建与快照 在Xenserver上可以创建Windows和Linux等虚拟机,Xenserver支持大部分的主流操作系统,可以使用 XenCe ...

  2. EM算法详解

    EM算法详解 1 极大似然估计 假设有如图1的X所示的抽取的n个学生某门课程的成绩,又知学生的成绩符合高斯分布f(x|μ,σ2),求学生的成绩最符合哪种高斯分布,即μ和σ2最优值是什么? 图1 学生成 ...

  3. enode框架step by step之saga的思想与实现

    enode框架step by step之saga的思想与实现 enode框架系列step by step文章系列索引: 分享一个基于DDD以及事件驱动架构(EDA)的应用开发框架enode enode ...

  4. 安装javajava整合Flex

    PS:今天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘.目前又不当COO,还是得用心记代码哦! 这几天在学一个叫Flex的东西,之前也没搞过这一类的东西认为既神秘又生疏,随 ...

  5. 如何在CMD下运用管理员权限

    方法一:鼠标右键 这个方法比较比较普通, 点开开始找到cmd,右击鼠标“以管理员身份运行(A)”这样调用就是管理员的权限: 方法二:快捷模式 在点开win+R后,选择“以管理员身份运行”,然后确定:可 ...

  6. OC之OC与C的比较

    1. 从编写.编译.链接的流程. 1). 创建1个.m的源文件. 2). 在这个文件中写上符合OC语法规范的源代码. 3). 编译. a. 预编译: 执行预处理代码. b. 检查语法. c. 生成目标 ...

  7. java基础练习 1

    import java.util.Scanner; public class First { /* * 编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n,当输入n为奇数时,调用函 ...

  8. 使用div模拟textarea,实现文本输入框高度自适应(附:js控制textarea实现文本输入框高度自适应)

    一.使用textarea标签进行多行文本的输入有很多限制,比如不能实现高度自适应,会出现难看的滚动条等问题. HTML5中添加了一个新属性contenteditable,该属性可以让input,tex ...

  9. Android JDK配置使支持Gradle更新,Maven安装

    配置Maven 或执行Gradle更新等相关命令时出现以下错误时要重新配置JDK ERROR: JAVA_HOME is set to an invalid directory.JAVA_HOME = ...

  10. Codevs 4189 字典

    4189 字典 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题目描述 Description 最经,skyzhong得到了一本好厉害的字典,这个字典里整整有n ...