zoukankan      html  css  js  c++  java
  • 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/556/problem/B

    Description

    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.

    Sample Input

    3
    1 0 0

    Sample Output

    Yes

    HINT

    题意

    给n个齿轮,每按一下,这些齿轮都会转

    奇数位和偶数位的转动方向不一样

    最后问能不能变成0,1,2,3,4...n-1

    题解:

    假设第一位方向是+1,那么就实质上第一个数就确定了转多少下了

    于是判一下就好了

    代码

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef unsigned long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 2000001
    #define mod 1000000007
    #define eps 1e-9
    int Num;
    char CH[20];
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    //**************************************************************************************
    
    int main()
    {
        int n,d;
        cin >> n >> d;
        for(int i = 1; i < n; ++i)
        {
            int a;
            cin >> a;
            if(i!=(a+d*(i&1?1:-1)+n)%n)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
  • 相关阅读:
    PAT 天梯赛 L1-002 【递归】
    HDU_2717_Catch That Cow
    Stock Exchange (最大上升子子串)
    Lorenzo Von Matterhorn(map的用法)
    Ignatius and the Princess IV (简单DP,排序)
    投掷硬币(概率dp)
    Find The Multiple (DFS递归)
    24 Game
    棋盘问题
    linux上的文件服务
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4605032.html
Copyright © 2011-2022 走看看