Title Link: Http://codeforces.com/problemset/problem/556/B
Title meaning: Give n gears, each gear has n teeth, counter-clockwise arrangement, numbered 0 ~ n-1. Each time the button is pressed, each gear will have and only one active tooth, and for even numbered gears, its next active tooth is the one next to the current tooth counterclockwise direction, while the odd numbered gear, the next activity tooth, is the clockwise one. Given the activity of each gear tooth, ask to be able to get a 0,1,...,n-2,n-1 sequence by pressing the button for a finite number of times.
Leave the school first game! I'm so miserable and speechless ~ ~ ~
Made some low-level errors, input and output problems = =; Then the problem is complicated, and even the algorithm is wrong. Enter the time with int, then to char save, so strcmp compare ... Then we calculate the new tooth and then return to int .... The mistake is to change the input from int to char, and calculate the position of the new tooth.
For example, there are sequences like this:
15
2 14 4 1 6 3 8 5 10 7 12 9 14 11 1
ref:0 ~ n-1 Char
S: the original sequence of inputs is converted to Char
And then calculate the new position,
Odd Gear Calculation formula: x = (x-1+n)% n;
Even gear calculation formula: x = (x+1+n)% n
The problem is on the X, note that ref 10, 11, after the position, not the corresponding Arabic numerals, is the character, and the formula is for the number to calculate the new tooth position. This leads to the following conditions (listed 10 times):
It is imagined that is ah hehe .... = =
Finally I will do with an int array to do, blood and tears of the lesson! Step by step simulation, don't think too much.
Here to talk about the cycle end condition, only need to test 1000 times on it, because for each gear, the activity tooth is the cycle, the test 1000 times can be a gear every tooth are tried, in fact, all gears is 1000 sequence situation well ~ ~ ~ Sync yo.
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6 using namespacestd;7 8 Const intMAXN = ++5;9 intA[MAXN];Ten One intMain () A { - #ifndef Online_judge -Freopen ("In.txt","R", stdin); the #endif //Online_judge - - intN; - while(SCANF ("%d", &n)! =EOF) { + - for(inti =0; I < n; i++) { +CIN >>A[i]; A } at BOOLFlag =true; - intCNT =0; - while(CNT <MAXN) { -Flag =true; -cnt++; - for(inti =0; I < n; i++) { in if(A[i]! =i) { -Flag =false; to Break; + } - } the if(flag) { * Break; $ }Panax Notoginseng - Else { the for(inti =0; I < n; i++) { + if(I &1) { AA[i] = (A[i]-1+ N)%N; the } + Else { -A[i] = (A[i] +1) %N; $ } $ } - } - } theprintf"%s\n", Flag?"Yes":"No"); - }Wuyi return 0; the}View Code
Codeforces 556B. Case of Fake Numbers problem Solving report