codeforces 777A 题目解答:奇数次操作交换 1,2 位置的东西; 偶数此操作交换 2,3 位置的东西,给你操作的次数, 和最后的位置; 问你一开始的位置在哪里。
【题解】
- /* 一开始在0位置 1 2 3 4 5 6 1 2 2 1 0 0 这就是一个循环,到了第6次操作又回到了初始状态; n%6 == 1 - > 1 == 2 ->2 ... == 0 ->0 ->最终的位置就和n%6的值有关; 在1位置 1 2 3 4 5 6 0 0 1 2 2 1 第6次操作就回到了初始状态; 在2位置 1 2 3 4 5 6 2 1 0 0 1 2 第6次操作回到初始状态 枚举一开始的位置就好;看看哪个和答案符合;*/
【完整代码】
- #include using namespace std;#define lson l,
- m,
- rt << 1#define rson m + 1,
- r,
- rt << 1 | 1#define LL long long#define rep1(i, a, b) for (int i = a; i <= b; i++)#define rep2(i, a, b) for (int i = a; i >= b; i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d", &x)#define rel(x) scanf("%lld", &x) typedef pair pii;
- typedef pair pll;
- const int dx[9] = {
- 0,
- 1,
- -1,
- 0,
- 0,
- -1,
- -1,
- 1,
- 1
- };
- const int dy[9] = {
- 0,
- 0,
- 0,
- -1,
- 1,
- -1,
- 1,
- -1,
- 1
- };
- const double pi = acos( - 1.0);
- const int N = 110;
- int zero[7] = { - 1,
- 1,
- 2,
- 2,
- 1,
- 0,
- 0
- };
- int one[7] = { - 1,
- 0,
- 0,
- 1,
- 2,
- 2,
- 1
- };
- int two[7] = { - 1,
- 2,
- 1,
- 0,
- 0,
- 1,
- 2
- };
- LL n;
- int x;
- int main() { //freopen("F:\\rush.txt", "r", stdin); rel(n); rei(x); LL temp = n % 6; if (temp == 0) temp = 6; if (zero[temp] == x) { puts("0"); return 0; } if (one[temp] == x) { puts("1"); return 0; } if (two[temp] == x) { puts("2"); return 0; } return 0;}
就爱阅读 www.92to.com 网友整理上传, 为您提供最全的知识大全, 期待您的分享,转载请注明出处。
来源: http://www.92to.com/bangong/2017/02-25/17598213.html