50119. Paper, Scissors, Stone
難度:2.3/51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#include <stdio.h>
#include <stdlib.h>
#define max(a,b) ((a)>(b)?(a):(b))
int x, a, b, c;
int y, d, e, f;
int n;
int step(int x, int a, int b, int c){
return (a * x + b) % c;
}
// p = 0
// s = 1
// r = 2
int get_win(int x, int y){
x %= 3, y %= 3;
if(x == y) return 0;
if((x == 2 && y == 1) || (x == 1 && y == 0) || (x == 0 && y == 2)) return 1;
return -1;
}
static inline void solve(){
int cnt = 0;
while(1){
cnt++;
int rtv = get_win(x, y);
x = step(x, a, b, c);
y = step(y, d, e, f);
if(rtv == 0) continue;
if(rtv == 1) printf("%d %d\n", 0, cnt);
else printf("%d %d\n", 1, cnt);
break;
}
}
int main(){
scanf("%d %d %d %d", &x, &a, &b, &c);
scanf("%d %d %d %d", &y, &d, &e, &f);
scanf("%d", &n);
while(n--){
solve();
}
}