您的位置:首页 > 其它

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

2015-06-29 16:56 316 查看
题目传送门

 /*
题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1
构造:先求出使第1个指向0要多少步,按照这个次数之后的能否满足要求
题目读的好累:(
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

const int MAXN = 1e3 + 10;
const int INF = 0x3f3f3f3f;
int a[MAXN];

int main(void)      //Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
{
// freopen ("B.in", "r", stdin);

int n;
while (scanf ("%d", &n) == 1)
{
for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]);
int cnt = 0;
if (a[1] != 0)
{
cnt = (n - 1) - a[1] + 1;
}

bool flag = true;
for (int i=2; i<=n; ++i)
{
if (i & 1)
{
for (int j=1; j<=cnt; ++j)
{
a[i]++;
if (a[i] == n)    a[i] = 0;
}
if (a[i] != i - 1)    {flag = false;    break;}
}
else
{
for (int j=1; j<=cnt; ++j)
{
a[i]--;
if (a[i] == -1)    a[i] = n - 1;
}
if (a[i] != i - 1)    {flag = false;    break;}
}
}

(flag) ? puts ("Yes") : puts ("No");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: