CodeForces-556B Case of Fake Numbers
来源:互联网 发布:怎么看淘宝时间 编辑:程序博客网 时间:2024/05/21 18:58
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 1e3 + 5;int gear[maxn];int n;bool flag;int main(){ while(~scanf("%d", & n)) { for(int i = 0; i < n; i ++) scanf("%d", & gear[i]); for(int i = 1; i <= n; i ++) { flag = true; for(int j = 0; j < n; j ++) { if(gear[j] == j) continue; else { flag = false; break; } } if(flag) goto END; for(int j = 0; j < n; j ++) { if(j % 2 == 0) { gear[j] ++; if(gear[j] > n - 1) gear[j] = 0; } else { gear[j] --; if(gear[j] < 0) gear[j] = n - 1; } } } END: if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
题意:第一行输入一个n。表示齿轮的数量。奇数下标齿轮顺时针转动,偶数下标齿轮逆时针转动。判断最后是否能能经过转动产生顺序数字012345.....可以输出Yes。
题解:改变数最多改变n次(第一个for循环),flag 判断是否找到。 第二个for循环 判断 是否符合题意01234....如果符合的话 可以直接goto跳出。如果不符合的话 就要继续变化。下标是从0开始的,所以偶数顺时针+1,奇数逆时针-1。如果顺时针+1超过n-1则变回0,如果逆时针-1小于0则变回n-1。
0 0
- CodeForces-556B Case of Fake Numbers
- codeforces 556B Case of Fake Numbers
- Codeforces 556B Case of Fake Numbers 数字转盘
- 【66.47%】【codeforces 556B】Case of Fake Numbers
- B. Case of Fake Numbers
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
- Case of Fake Numbers
- B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)
- CF#310-B - Case of Fake Numbers-模拟水题
- Codeforces 555B Case of Fugitive 搭桥
- codeforces #310 B B. Case of Fugitive(贪心)
- Fake Numbers
- Codeforces 555B Case of Fugitive 排序+贪心
- Codeforces Round #310 (Div. 1) B. Case of Fugitive
- Codeforces Round #310 (Div. 1) B. Case of Fugitive
- Codeforces Round #310 (Div. 1) B. Case of Fugitive 贪心
- Codeforces Round #411(A. Fake NP; B. 3-palindrome; C. Find Amir; D.Minimum number of steps)
- codeforces 556 D Case of Fugitive
- 华为2016机试题
- n皇后问题
- hdoj 1162 Eddy's picture
- UINavigationController && UIStatusBar 导航控制器 && 状态栏
- (转)使用DDMS中的内存监测工具Heap来优化内存
- CodeForces-556B Case of Fake Numbers
- [leetcode] String to Integer (atoi)
- 小马哥--高仿LG G3 新版机型外观展示与开机界面图
- Java中的数学函数
- Java IO:了解I/O模型
- emacs org mode 表格使用
- Antenna Placement
- UI11_block练习
- uva 10110 平方数的因子有奇数个