交互题汇

1.Codeforces679A Bear and Prime 100

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 char fb[5];
 5 int init[40] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 4, 9, 25, 49};
 6 
 7 int main() {
 8     int cnt = 0; bool flag = 1;
 9     for (int i = 0; i <= 18; ++i){
10         printf("%d\n", init[i]);
11         fflush(stdout);
12         scanf("%s", fb);
13         if (fb[0] == 'y') ++cnt;
14         if (cnt >= 2) {
15             flag = 0; break;
16         }
17     }
18     flag ? puts("prime") : puts("composite");
19     return 0;
20 }
View Code

2.Codeforces1088D Ehab and another another xor problem

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n, a, b;
 5 
 6 inline int ask(int c, int d) {
 7     printf("? %d %d\n", c, d);
 8     fflush(stdout);
 9     int rt; scanf("%d", &rt);
10     return rt;
11 }
12 
13 int main() {
14     int big = ask(0, 0);
15     for (int i = 29; i >= 0; --i) {
16         int f = ask(a ^ (1 << i), b), s = ask(a, b ^ (1 << i));
17         if (f == s) {
18             if (big == 1) a ^= (1 << i);
19             else b ^= (1 << i);
20             big = f;
21         }
22         else if (f == -1) {
23             a ^= (1 << i), b ^= (1 << i);
24         }
25     }
26     printf("! %d %d\n", a, b);
27     return 0;
28 }
View Code

 

posted @ 2019-08-08 10:05  euix  阅读(119)  评论(0编辑  收藏  举报