zoukankan      html  css  js  c++  java
  • 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门

     1 /*
     2     题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1
     3     构造:先求出使第1个指向0要多少步,按照这个次数之后的能否满足要求
     4     题目读的好累:(
     5 */
     6 #include <cstdio>
     7 #include <iostream>
     8 #include <algorithm>
     9 #include <cstring>
    10 #include <cmath>
    11 using namespace std;
    12 
    13 const int MAXN = 1e3 + 10;
    14 const int INF = 0x3f3f3f3f;
    15 int a[MAXN];
    16 
    17 int main(void)      //Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
    18 {
    19     // freopen ("B.in", "r", stdin);
    20 
    21     int n;
    22     while (scanf ("%d", &n) == 1)
    23     {
    24         for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]);
    25         int cnt = 0;
    26         if (a[1] != 0)
    27         {
    28             cnt = (n - 1) - a[1] + 1;
    29         }
    30 
    31         bool flag = true;
    32         for (int i=2; i<=n; ++i)
    33         {
    34             if (i & 1)
    35             {
    36                 for (int j=1; j<=cnt; ++j)
    37                 {
    38                     a[i]++;
    39                     if (a[i] == n)    a[i] = 0;
    40                 }
    41                 if (a[i] != i - 1)    {flag = false;    break;}
    42             }
    43             else
    44             {
    45                 for (int j=1; j<=cnt; ++j)
    46                 {
    47                     a[i]--;
    48                     if (a[i] == -1)    a[i] = n - 1;
    49                 }
    50                 if (a[i] != i - 1)    {flag = false;    break;}
    51             }
    52         }
    53 
    54         (flag) ? puts ("Yes") : puts ("No");
    55     }
    56 
    57     return 0;
    58 }
    编译人生,运行世界!
  • 相关阅读:
    POJ
    UPC-5843: 摘樱桃(最优状态递推)
    BZOJ-1088 [SCOI2005]扫雷Mine(递推+思维)
    HDU-3065 病毒侵袭持续中(AC自动机)
    BZOJ-4236 JOIOJI (map查找+思维)
    HDU-2896 病毒侵袭(AC自动机)
    Hrbust-2060 截取方案数(KMP)
    UVALive 4490 压缩DP
    UVALive 5881
    UVALive 4168
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4607885.html
Copyright © 2011-2022 走看看