B. Case of Fake Numbers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

In a single line print "Yes" (without the quotes), if the given Stolp's gears puzzle is real, and "No" (without
the quotes) otherwise.

Examples
input
3
1 0 0
output
Yes
input
5
4 2 1 4 3
output
Yes
input
4
0 2 3 1
output
No
Note

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个齿轮,每个齿轮有n个齿。编号逆时针从0到n-1。第一个齿轮顺时针转带动第二个齿轮,于是第二个齿轮逆时针转又带动第三个齿轮,and so on..现在给定你一组序列作为初始序列判断经过若干次转动后是否能回到0 1 2 ...n-1。可以转任意次。

思路:首先看懂题,知道样例怎么来的这题基本就没什么问题了。我们可以逆着来推,假设初始序列为0 1 2...n-1,判断经过若干次转动后是否能到达给定状态,其实这n个齿轮转动一周后还是会回到初始状态,我们只需判断中间是否有某个状态符合条件。数据只有1000,所以两层循环即可。

const int N=1e5+10;
int a[1001],b[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++) scanf("%d",&a[i]);
int f=0;
for(int i=0;i<n;i++) b[i]=i;//初始状态。
for(int i=0;i<=n&&!f;i++)
{
for(int i=0;i<n;i++)//编号为偶数的顺时针转
if(i%2==0) b[i]=(b[i]+1)%n;
else b[i]=(b[i]-1+n)%n;
int x=0;
for(int i=0;i<n&&!x;i++)
if(a[i]!=b[i]) x=1;
if(!x) f=1;
}
if(f) printf("Yes\n");
else printf("No\n");
}
return 0;
}

大水题,,要敢于尝试和快速理解题意啊。。。

CodeForces 556 --Case of Fake Numbers的更多相关文章

  1. CodeForces - 556B Case of Fake Numbers

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  2. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  3. 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 ...

  4. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  5. B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)

    B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

  8. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  9. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

随机推荐

  1. 转 google 制作 邀请函

    http://blog.csdn.net/adali/article/details/8315619

  2. hash系列集合的性能优化

    hash系列的集合: HashSet.LinkedHashSet     采用hash算法决定元素在集合中的存储位置 HashMap.LinkedHashMap.Hashtable   采用hash算 ...

  3. JDK使用最多的模式之一--观察者模式

    公司接到新任务,需要做一个气象监测应用.该应用将实现三个界面:当前气象状态,气象统计以及气象预报.应用从WeatherObject对象中获取所需数据:温度,湿度,气压.当然,为了可扩展性,该应用同时也 ...

  4. spring-bean(三)

    配置方式:通过工厂方法配置bean,通过FactoryBean配置bean 配置形式:基于注解的方式 组件扫描 泛型依赖注入 静态工厂方法 /** * 静态工厂方法:直接调用某一个类的静态方法就可以返 ...

  5. CF781A Andryusha and Colored Balloons

    题意: Andryusha goes through a park each day. The squares and paths between them look boring to Andryu ...

  6. easybcd 支持 windows 10 和 ubuntu 14.04 双系统启动

    家里计算机系统 windows 10 全新安装. 原本是双系统的,还有一个ubuntu. windows 10 安装以后,恢复ubuntu就是问题了. (事后经验:请不要立刻安装bcd修改工具) 最初 ...

  7. 云梯互联:所有主机已全面支持免费SSL!附小白配置教程。

    HTTPS和HTTP的区别:1.HTTPS是加密传输协议,HTTP是名文传输协议;2.HTTPS需要用到SSL证书,而HTTP不用;3.HTTPS比HTTP更加安全,对搜索引擎更友好,利于SEO4. ...

  8. 写的一个HttpClient类

    package com.ca.test.cainterface.common.util.http; import com.ca.test.cainterface.common.util.data.Da ...

  9. 旅行商问题——状态压缩DP

    问题简介 有n个城市,每个城市间均有道路,一个推销员要从某个城市出发,到其余的n-1个城市一次且仅且一次,然后回到再回到出发点.问销售员应如何经过这些城市是他所走的路线最短? 用图论的语言描述就是:给 ...

  10. 富通天下(W 笔试)

    纸质算法题目 1.给你一个字符串,找出其中第一个只出现过一次的字符及其位置 正解:一层for循环,循环按序取出字符串中的单个字符,循环体内部使用String类的indexOf(),从当前字符下标往后搜 ...