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 ...
随机推荐
- 关于联想笔记本不能连接无线网(wifi),注销后重新登录才可以连接
解决联想笔记本wifi问题(果果) 最近很多使用联想的朋友都遇到了这样一个问题,那就是笔记本的wifi突然不能用了,好吧,其实我个人也遇到了这个问题,但是网上貌似对这个问题并没有给出一个可以解决的办法 ...
- 模式匹配第四弹:if case,guard case,for case
2016-06-06 7388 作者:Olivier Halligon,原文链接,原文日期:2016-05-16 译者:walkingway:校对:Cee:定稿:numbbbbb 现在我们来重新回顾下 ...
- 梦想CAD控件关于比较问题
全图比较 怎么比较两个CAD图纸文件修改前后的不同部分呢?在工程图纸设计中,我们更多情况下可能需要对同一张工程图的前后修改部分进行对比,以确定工程图纸的改动部分及追溯原因,本教程演示了几种常见的比较方 ...
- 梦想MxWeb3D,三维CAD协同设计平台 2019.05.05更新
SDK开发包下载地址: http://www.mxdraw.com/ndetail_20140.html 在线演示网址: http://www.mxdraw.com:3000/ 1. 增加CAD绘图 ...
- JavaScipt30(第七个案例)(主要知识点:数组some,every,findIndex方法)
承接上文,这是第7个案例,这个案例没什么说的,主要有三个注意点: 附上项目链接: https://github.com/wesbos/JavaScript30 // 1. slice(begin, e ...
- datetimebox赋值或取值
datetimebox赋值或取值 $('#j_dateStart').datebox('setValue', ""); //赋予空值 $("#j_dateStart&qu ...
- 微服务网关从零搭建——(一)创建测试api以及api自动注入consul
本系列编写目的纯属个人开发记录 以下代码均为demo级 如有需要 请自行优化 代码完整包由于公司电脑加密 无法上传整包的demo文件 consul 开发环境简易处理 consul 下载地址 : ht ...
- java计算两地距离(公里)
//目标经度,目标纬度,自己经度,自己纬度 public static double getDistance(double lon1, double lat1, double lon2, double ...
- form表单传输多余参数
1.使用post提交表单,同时在form的action属性后添加“?参数=参数值”,经验证,可行,但是在浏览器中看不到该参数在form参数中,如下图: 上图未出现courseId属性,form代码如下 ...
- Luogu P4316 绿豆蛙的归宿
P4316 绿豆蛙的归宿 题意翻译 「Poetize3」 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边 ...