zoukankan      html  css  js  c++  java
  • Codeforces Round #346 (Div. 2) A. Round House 水题

    A. Round House

    题目连接:

    http://www.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.

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

    Sample Output

    3

    Hint

    题意

    给你一个环形轨道,你一开始在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;
    }
  • 相关阅读:
    Leetcode 70 Climbing Stairs 递推
    Leetcode 83 Remove Duplicates from Sorted List 链表
    Leetcode 328 Odd Even Linked List 链表
    Leetcode 206 Reverse Linked List 链表
    Spring中注解
    SpringMVC配置文件
    java设计模式----单例模式
    java设计模式----工厂方法模式
    java设计模式----装饰者模式
    java设计模式----观察者模式
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5341880.html
Copyright © 2011-2022 走看看