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;
    }
  • 相关阅读:
    constraint更新表列约束默认值
    sql语句 关于日期时间、类型转换的东西
    SQL数据库完全复制
    SQLServer语句 汇总
    SQL Server Profiler使用方法
    SQL语句-批量插入表(表数据插表)
    VS 快捷键
    外部引用 jQuery 库
    mongodb笔记
    Ubuntu16.04安装live-server
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5341880.html
Copyright © 2011-2022 走看看