首页 > 其他 > 详细

交互题汇

时间:2019-08-08 11:57:40      阅读:93      评论:0      收藏:0      [点我收藏+]

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

 

交互题汇

原文:https://www.cnblogs.com/Fo0o0ol/p/11319500.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!