码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-29 19:18:20      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

 

 

题目传送门

 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 }

 

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

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4607885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!