关闭

Codeforces Round #346 (Div. 2)Round House(数学,找规律)

153人阅读 评论(0) 收藏 举报
分类:
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
Input
6 2 -5
Output
3
Input
5 1 3
Output
4
Input
3 2 7
Output

3

代码:

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int q[101];
		memset(q,0,sizeof(q));
		int a,b;
		scanf("%d %d",&a,&b);
		int p=b;
		q[1]=a;
		if(b<=0)
		{
			b=abs(b);
			b=b%n;
			for(int i=2;i<=n;i++)
		{
			if(i<=a)
			q[i]=a-i+1;
			else
			q[i]=n-i+1+a;
		}
		printf("%d\n",q[b+1]);
		}
		else
		{
			b=b%n;
			for(int i=2;i<=n;i++)
			{
				q[i]=a+i-1;
				if(q[i]>n)
				q[i]=q[i]-n;
			}
			printf("%d\n",q[b+1]);
		}
	}
	return 0;
}
题意:小明出去散步,告诉你围绕他家一圈多大。给他家排序,顺时针从1开始一直到n,还告诉你小明所在位置还有小明走了多少步b。b为负数就是逆时针走(坑到这了)。

然后问你小明最后在那个位置停住。

思路:先给小明家一圈编号,在判断b的正负值,最后根据规律输出最后所在位置就行。

0
0
查看评论

Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

A:Game With Sticks 水题。。。每次操作,都会拿走一个横行,一个竖行。 所以一共会操作min(横行,竖行)次。 #include #include #include #include #include #include #include #include #pragma commen...
  • rowanhaoa
  • rowanhaoa
  • 2014-07-25 14:39
  • 1479

【解题报告】Codeforces Round #401 (Div. 2)

简略的解题报告。
  • TRiddle
  • TRiddle
  • 2017-02-25 17:55
  • 413

Codeforces Round #395 (Div. 2)(ABCD)

ps:打完这场cf才知道自己真的很菜,还是停留在AB题的水平,有时候CD其实很简单,但就是想不到,别人一眼看出而我就是想不到,有时候想到了点子上但就是突破不了 题目链接:  Codeforces Round #395 (Div. 2) A题: &...
  • qq_34731703
  • qq_34731703
  • 2017-02-03 12:50
  • 496

Codeforces Round #378 (Div. 2) E. Sleep in Class

链接:http://codeforces.com/contest/733/problem/E 题意:给一个只含'U'和'D'的字符串,U表示向右走,D表示向左走。每个格子踩一次之后翻转(U变D,D变U),求从每个格子出发走多少步才能走到位置小于1或大于n。 分析:...
  • Fsss_7
  • Fsss_7
  • 2016-11-15 13:48
  • 359

Codeforces Round #460 (Div. 2) D. Substring(拓扑排序)

题目链接题意:有一个n个点m条边的有向图,每个节点有一个字母,路径的权值是路径上相同字母的最大个数。求最大的路径权值。思路:因为只有26个字母,所以直接假设其中一个字母为相同字母数最大的字母。枚举每一个字母,通过拓扑排序找到最大权值,取其中的最大值就是答案。当图中存在环时,答案就是无穷大,输出-1;...
  • cyf199775
  • cyf199775
  • 2018-02-01 13:55
  • 39

Codeforces Round #442 (Div. 2)

A. #include using namespace std; typedef long long ll; int main() { string s; cin >> s; vector v; v.push_back ("Danil&quo...
  • Egqawkq
  • Egqawkq
  • 2017-10-24 02:15
  • 239

Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)

D. Winter is here time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Winter is h...
  • Jaihk662
  • Jaihk662
  • 2017-08-14 14:52
  • 349

Codeforces Round #427 (Div. 2) A B C D

A. Key races time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two boys decided ...
  • sinat_35406909
  • sinat_35406909
  • 2017-08-01 02:03
  • 699

Codeforces Round #327 (div.2)(A B C D)

codeforces round #327 (div.2)
  • lincifer
  • lincifer
  • 2015-10-26 13:11
  • 1094

Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B

A. Gotta Catch Em’ All!time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard outputBash wants to become a...
  • qq_33183401
  • qq_33183401
  • 2017-01-16 17:12
  • 243
    个人资料
    • 访问:39841次
    • 积分:2790
    • 等级:
    • 排名:第15172名
    • 原创:248篇
    • 转载:13篇
    • 译文:0篇
    • 评论:4条