B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)
2 seconds
256 megabytes
standard input
standard output
Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was.
Its most important components are a button and a line of n similar gears. Each gear has n teeth
containing all numbers from 0 to n - 1 in
the counter-clockwise order. When you push a button, the first gear rotates clockwise, then the second gear rotates counter-clockwise,
the the third gear rotates clockwise an so on.
Besides, each gear has exactly one active tooth. When a gear turns, a new active tooth is the one following after the current active tooth according to the direction of the rotation. For example, if n = 5,
and the active tooth is the one containing number 0, then clockwise rotation makes the tooth with number 1 active,
or the counter-clockwise rotating makes the tooth number 4 active.
Andrewid remembers that the real puzzle has the following property: you can push the button multiple times in such a way that in the end the numbers on the active teeth of the gears from first to last form sequence 0, 1, 2, ..., n - 1.
Write a program that determines whether the given puzzle is real or fake.
The first line contains integer n (1 ≤ n ≤ 1000)
— the number of gears.
The second line contains n digits a1, a2, ..., an (0 ≤ ai ≤ n - 1)
— the sequence of active teeth: the active tooth of the i-th gear contains number ai.
In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without
the quotes) otherwise.
3
1 0 0
Yes
5
4 2 1 4 3
Yes
4
0 2 3 1
No
In the first sample test when you push the button for the first time, the sequence of active teeth will be 2 2 1, when you push it for the second
time, you get 0 1 2.
题意:有n个转盘,在位置上分别为1-n,每一个转盘上在一圈分别写着0 -- n-1,
如今有一个button,每一次按这个button。每一个转盘都会发生一些变化,详细的变化是:
1.转盘在奇数位的。转盘上面的数字+1(也就是顺时针旋转)。
2.转盘在偶数位的,转盘上面的数字-1(也就是逆时针旋转)。
问能不能在摁下n次button后,使得第i个转盘上面的数字就是i-1。
思路:推断一下第一个转盘为0时。其它的转盘是不是满足第i个转盘的数字为i-1。不满足直接输出No。
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stack> using namespace std; int n;
int a[1005]; int main() {
while(scanf("%d",&n)!=EOF) {
for(int i=1; i<=n; i++) {
scanf("%d",&a[i]);
}
while(a[1] != 0) {
for(int i=1; i<=n; i++) {
if(i%2 == 1) {
a[i] += 1;
a[i] = a[i]%n;
} else {
a[i] -= 1;
if(a[i]<0){
a[i] = n + a[i];
}
}
}
}
int flag = 0;
for(int i=1;i<=n;i++){
if(a[i] != i-1)
{
flag = 1;
break;
}
}
if(flag == 1){
printf("No\n");
}
else{
printf("Yes\n");
}
}
return 0;
}
B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)的更多相关文章
- 「日常训练」Case of Matryoshkas(Codeforces Round #310 Div. 2 C)
题意与分析(CodeForces 556C) 为了将所有\(n\)个娃娃编号递增地串在一起(原先是若干个串,每个串是递增的), 我们有两种操作: 拆出当前串中最大编号的娃娃(且一定是最右边的娃娃). ...
- B. Simple Game( Codeforces Round #316 (Div. 2) 简单题)
B. Simple Game time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- B. Vanya and Books( Codeforces Round #308 (Div. 2) 简单题)
B. Vanya and Books time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones
题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
随机推荐
- Microsoft SQL Server学习(七)--函数视图
系统函数 视图 索引 1.系统函数 (1) ()数学函数 Abs() 绝对值 Floor() 向下取整 Ceiling() 向上取整 Sin() 返回指定角度(以弧度为单位)的三角正弦值 Pi() 圆 ...
- Farseer.net轻量级开源框架 入门篇:修改数据详解
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 添加数据详解 下一篇:Farseer.net轻量级开源框架 入门篇: 删除数据详解 ...
- axios 正确打开方式
一.安装1. 利用npm安装npm install axios --save2. 利用bower安装bower install axios --save3. 直接利用cdn引入<script s ...
- 新开的坑-python学习笔记(1)——连接符与转义
1/print输出格式虽然知道怎么用却还要打破砂锅的问问题... 问题答案是 需要读很多基础文档教程 --------例如 "+" . "," 作为连接符的作 ...
- PHP数据乱码
本文主要总结下PHP数据乱码的解决方案 要点:多个不同文件系统里一定要统一编码 [注意] (1)HTML编码与MySQL编码一致: (2)PHP编码与MySQL编码一致: (3)header头发送字符 ...
- buf.readDoubleBE()
buf.readDoubleBE(offset[, noAssert]) buf.readDoubleLE(offset[, noAssert]) offset {Number} 0 <= of ...
- idea14远程调试linux下的tomcat
进入到idea的tomcat的run/debug配置,新建个remote tomcat,然后填写相关信息,如上图(注意远程调试端口). 再选择Startup/Connection,如下图所示: 到此, ...
- Multisim破解教程
转载:http://www.121down.com/article/article_52879.html
- 洛谷 4364 [九省联考2018]IIIDX
[题解] 一眼可以想到一个类似二叉树后序遍历的贪心做法,然而这个做法在有相同数字的情况下是错误的.最简单的反例就是n=4,d={1,1,1,2},正解是1,1,2,1,而贪心是1,1,1,2. 所以这 ...
- PAT 1133 Splitting A Linked List
Given a singly linked list, you are supposed to rearrange its elements so that all the negative valu ...