• CodeForces


    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.

    Android安卓是一个银河系著名的侦探。他现在正在调查一宗欺诈案,这些案子仿制了著名的Stolp齿轮,这些谜题与Rubik的立方体一样著名。

    它最重要的组件是一个按钮和一行n个相似的齿轮。每个齿轮有n个齿,按逆时针顺序包含从0到n-1的所有数字。按下按钮时,第一个齿轮顺时针旋转,然后第二个齿轮逆时针旋转,第三个齿轮顺时针旋转,依此类推。

    此外,每个齿轮只有一个活动齿。当齿轮旋转时,根据旋转方向,新的活动齿是当前活动齿之后的下一活动齿。例如,如果n = 5,并且活动的牙齿是包含数字0的那个,那么顺时针旋转将使数字1的牙齿活动,或者逆时针旋转将数字4的牙齿活动。

    Andrewid记得真正的谜题具有以下特性:您可以多次按下按钮,使得齿轮的有效齿上的数字从第一个到最后一个形成序列0,1,2,。 ,n-1.编写一个程序,确定给定的拼图是真还是假。

    输入值
    第一行包含整数n(1≤n≤1000)-齿轮数。

    第二行包含n个数字a1,a2,…,an(0≤ai≤n-1)—主动齿的顺序:第i个齿轮的主动齿包含数字ai。

    输出量
    如果给定的Stolp齿轮拼图是真实的,则单行打印“是”(不带引号),否则为“否”(不带引号)。

    例子
    输入值
    3
    1 0 0
    输出
    Yes
    输入
    5
    4 2 1 4 3
    输出
    Yes
    输入
    4
    0 2 3 1
    输出
    No
    注意
    在第一次按下按钮的第一个样本测试中,活动牙齿的顺序将为2 2 1,第二次按下按钮时,将得到0 1 2。

    题目大意:给出n个齿轮,每次操作都会使编号为奇数的齿轮值+1,编号为偶数的齿轮值-1,询问能否经过多次操作后变成0 1 2 … 这样的序列

    解题思路:这是一道模拟题,因为有n个齿轮和这样的操作,因此在操作n次后一定会回到最初始的状态,所以模拟n次齿轮变化即可,然后判断每次操作是否能变成要求的序列。AC代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int _max=1e3+50;
    int a[_max],b[_max];
    int n;
    int main()
    {
    	int cnt=1;
    	bool flag=false;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	  cin>>a[i];//读入原始序列
    	for(int i=1;i<=n;i++)
    	  b[i]=i-1;//最后要求的序列
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n;j++)
    		  if(j&1)//奇数+1
    		  {
    		  	a[j]++;
    		  	if(a[j]==n)
    		  	  a[j]=0;
    		  }
    		  else//偶数-1
    		  {
    		  	a[j]--;
    		  	if(a[j]<0)
    		  	  a[j]=n-1;
    		  }
    		for(int j=1;j<=n;j++)//一操作一判断
    		  if(a[j]!=b[j])
    		    break;
    		  else
    		    cnt++;
    		if(cnt==n+1)
    		{
    			flag=true;
    			break;
    		}  
    	}
    	if(flag)
    	  cout<<"Yes"<<endl;
    	else
    	  cout<<"No"<<endl;
    	return 0;    
    }
    
  • 相关阅读:
    js调用手机震动
    模拟器 Android Studio
    不修改代码,让调用方法 替换到另外一个方法
    springboot 获取请求 / 响应 接收和设置请求头 、请求码的方法
    mysql binlog 实现数据库同步先占位 有空研究下
    Airtest无线连接android手机
    springboot + spring cloudeureka
    更新一条数据多个字段的方法
    PyAutoGUI 操作C端 识别图片 点击(有空就看一下) 可以替代 Autoit
    playwright入门
  • 原文地址:https://www.cnblogs.com/Hayasaka/p/14294307.html
Copyright © 2020-2023  润新知