/////////////////////////////////////////////////////////////////////////////////////////////////////// 
作者:stxy-ferryman
声明:本文遵循以下协议自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 
查看本文更新与讨论请点击:http://www.cnblogs.com/stxy-ferryman/
链接被删请百度:stxy-ferryman
///////////////////////////////////////////////////////////////////////////////////////////////////////

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.

Example

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个齿轮,依次相接,齿轮示数为ai,按下某个不可名状的东西以后,奇数齿轮顺时针旋转(示数+1),偶数齿轮逆时针旋转(示数-1),如果能转出0,1,2....n-1则输出yes否则输出no

题解:转一遍,检验一遍,对则输出yes,如果转完n次仍不能成功,那就没有什么价值继续了,输出no

当然,有o(n)算法http://paste.ubuntu.com/11788578/

代码:

var
b:boolean;
n,i,j,k:longint;
a:array[..] of longint;
function jy(n:longint):boolean;
begin
for i:= to n do
if a[i]<>i- then exit(false);
exit(true);
end;
begin
readln(n);
for i:= to n do
read(a[i]);
b:=true;
while (not jy(n)) do
begin
for i:= to n do
begin
if i mod = then inc(a[i])
else dec(a[i]);
if a[i]< then a[i]:=n-;
if a[i]>n- then a[i]:=;
end;
inc(k);
if k>n then begin b:=false; break; end;
end;
if b then writeln('Yes')
else writeln('No');
end.

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

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

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

  2. CodeForces 556 --Case of Fake Numbers

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

  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. PHPFastCGI进程管理器PHP-FPM详解

    PHP-FPM是一个PHPFastCGI进程管理器,是只用于PHP的.      PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中.必须将它patch到你的PH ...

  2. cglib代理

    简介: github地址:https://github.com/cglib/cglib,可以访问这个地址查看cglib源码和相关文档. 简单的摘录了wiki上关于cglib的描述: cglib is ...

  3. Spring Framework 5.0 新特性

    Spring Framework 5.0是在Spring Framework 4.0之后将近四年内一次重大的升级. 在这个时间框架内,主要的发展之一就是Spring Boot项目的演变. Spring ...

  4. Reverse Words in a String III

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  5. 【JAVA零基础入门系列】Day3 Java基本数据类型

    前两篇已经将开发环境搭建完成,如果你已经按之前的教程按部就班的完成了部署,那么世界上最优秀的编程语言之一和世界上最优秀的IDE之一已经出现在你的电脑上(此处应有掌声),如果你还没入门,或者正在台阶上踱 ...

  6. windows phone 模拟器

    window phone 模拟器启动报错 修改Bios设置,我的是yoga pro 2,只修改 即可.启动成功

  7. SerialPort如何读取串口数据并显示在TextBox上,多线程委托

    namespace SerialPort { public partial class Form3 : Form { delegate void UpdateTextEventHandler(stri ...

  8. akka源码导读

    akka的actor模型提供了强大的并发,本人就akka源码进行了详细的阅读,下面是一些体会. 1.object SystemMessageList: @tailrec private[sysmsg] ...

  9. cocos2dx - 伤害实现

    接上一节内容:cocos2dx - 生成怪物及AI 本节主要讲如何通过创建简单的矩形区域来造成伤害 在小游戏中简单的碰撞需求应用box2d等引擎会显得过于臃肿复杂,且功能不是根据需求定制,还要封装,为 ...

  10. 【JDK1.8】Java 8源码阅读汇总

    一.前言 ​ 万丈高楼平地起,相信要想学好java,仅仅掌握基础的语法是远远不够的,从今天起,笔者将和园友们一起阅读jdk1.8的源码,并将阅读重点放在常见的诸如collection集合以及concu ...