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 ...
随机推荐
- Clickhouse DDL&DML
(1)添加列: alter table [db.]table_name add column column_name [type] [default_expr] [after name_after] ...
- Spring Boot 创建hello world项目
Spring Boot 创建hello world项目 1.创建项目 最近在学习Spring Boot,这里记录使用IDEA创建Spring Boot的的过程 在1出勾选,选择2,点击Next 这里填 ...
- Eigen库笔记整理(一)
首先熟悉Eigen库的用途,自行百度. 引入头文件: // Eigen 部分 #include <Eigen/Core> // 稠密矩阵的代数运算(逆,特征值等) #include < ...
- Install Zabbix with Docker
1. mysql -uroot -p -h10.10.0.242 zabbix<schema.sqlEnter password: * ERROR 1709 (HY000) at line 86 ...
- RESTful API设计的简单例子
代码承接简单服务器,修改 app.js const koa = require('koa'), app = new koa(), Router = require('koa-router'), rou ...
- Python orm基础
ORM 对象映射关系程序. 通过orm将编程语言的对象模型和数据库的关系模型建立映射关系,这样我们在使用编程语言对数据库进行操作的时候可以直接使用编程语言的对象模型进行操作就可以了,而不用直接使用sq ...
- 面向对象程序设计--Java语言第三周编程题:查找里程
查找里程 题目内容: 下图为国内主要城市之间的公路里程: 你的程序要读入这样的一张表,然后,根据输入的两个城市的名称,给出这两个城市之间的里程. 注意:任何两个城市之间的里程都已经给出,不需要计算经第 ...
- TWaver 3D应用于大型数据中心(续)
在2014年11月份,我们当时发了一篇有关TWaver HTML5 3D应用于大型数据中心的文章,该blog比较详细的描述一些常用的功能的实现方法,比如:动态添加机柜,告警,温度,湿度等相关的功能的具 ...
- 巧用TWaver 3D 矢量图形功能
的确,提起TWaver,大家想到的首先是“电信拓扑图组件”.其实,由于其灵活的MVC架构.矢量化设计.方便定制等特点,TWaver可以做的还有很多.例如房地产行业常见到的“户型图”. 户型推荐是销售接 ...
- Gym - 101670J Punching Power(CTU Open Contest 2017 最大独立集)
题目: The park management finally decided to install some popular boxing machines at various strategic ...