传送门:https://codeforces.com/contest/1167/problem/B

题意:

交互题:现在你有6个数4, 8, 15, 16, 23, 42组成的某种组合,你可以询问系统四次,每次询问的格式为?i j

系统会回复你ai*aj的值,问你这个组合是哪种,有解且解是唯一的

题解:

交互题技巧,cin,cout可以自动刷新,而scanf,printf则需要手动用fflush(stdout)来刷新

根据观察我们可以发现,这六个数两两乘积不相等,所以a1*a2 a2*a3这样的解是唯一的,并且只有六个数,我们用next_permatation全排列函数可以得到结果

代码:

  1. /**
  2. *        ┏┓    ┏┓
  3. *        ┏┛┗━━━━━━━┛┗━━━┓
  4. *        ┃       ┃  
  5. *        ┃   ━    ┃
  6. *        ┃ >   < ┃
  7. *        ┃       ┃
  8. *        ┃... ⌒ ...  ┃
  9. *        ┃       ┃
  10. *        ┗━┓   ┏━┛
  11. *          ┃   ┃ Code is far away from bug with the animal protecting          
  12. *          ┃   ┃ 神兽保佑,代码无bug
  13. *          ┃   ┃           
  14. *          ┃   ┃       
  15. *          ┃   ┃
  16. *          ┃   ┃           
  17. *          ┃   ┗━━━┓
  18. *          ┃       ┣┓
  19. *          ┃       ┏┛
  20. *          ┗┓┓┏━┳┓┏┛
  21. *           ┃┫┫ ┃┫┫
  22. *           ┗┻┛ ┗┻┛
  23. */
  24. // warm heart, wagging tail,and a smile just for you!
  25. //
  26. // _ooOoo_
  27. // o8888888o
  28. // 88" . "88
  29. // (| -_- |)
  30. // O\ = /O
  31. // ____/`---'\____
  32. // .' \| |// `.
  33. // / \||| : |||// \
  34. // / _||||| -:- |||||- \
  35. // | | \\ - /// | |
  36. // | \_| ''\---/'' | |
  37. // \ .-\__ `-` ___/-. /
  38. // ___`. .' /--.--\ `. . __
  39. // ."" '< `.___\_<|>_/___.' >'"".
  40. // | | : `- \`.;`\ _ /`;.`/ - ` : | |
  41. // \ \ `-. \_ __\ /__ _/ .-` / /
  42. // ======`-.____`-.___\_____/___.-`____.-'======
  43. // `=---='
  44. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  45. // 佛祖保佑 永无BUG
  46. #include <set>
  47. #include <map>
  48. #include <deque>
  49. #include <queue>
  50. #include <stack>
  51. #include <cmath>
  52. #include <ctime>
  53. #include <bitset>
  54. #include <cstdio>
  55. #include <string>
  56. #include <vector>
  57. #include <cstdlib>
  58. #include <cstring>
  59. #include <iostream>
  60. #include <algorithm>
  61. using namespace std;
  62. typedef long long LL;
  63. typedef pair<LL, LL> pLL;
  64. typedef pair<LL, int> pLi;
  65. typedef pair<int, LL> pil;;
  66. typedef pair<int, int> pii;
  67. typedef unsigned long long uLL;
  68. #define ls rt<<1
  69. #define rs rt<<1|1
  70. #define lson l,mid,rt<<1
  71. #define rson mid+1,r,rt<<1|1
  72. #define bug printf("*********\n")
  73. #define FIN freopen("input.txt","r",stdin);
  74. #define FON freopen("output.txt","w+",stdout);
  75. #define IO ios::sync_with_stdio(false),cin.tie(0)
  76. #define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
  77. #define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
  78. #define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
  79. const double eps = 1e-8;
  80. const int mod = 1e9 + 7;
  81. const int maxn = 3e5 + 5;
  82. const int INF = 0x3f3f3f3f;
  83. const LL INFLL = 0x3f3f3f3f3f3f3f3f;
  84. int main() {
  85. #ifndef ONLINE_JUDGE
  86. FIN
  87. #endif
  88. vector<int> v {4, 8, 15, 16, 23, 42};
  89. int a, b, c, d;
  90. cout << "? 1 2" << endl;
  91. cin >> a;
  92. cout << "? 2 3" << endl;
  93. cin >> b;
  94. cout << "? 4 5" << endl;
  95. cin >> c;
  96. cout << "? 5 6" << endl;
  97. cin >> d;
  98. do {
  99. if(v[0]*v[1] == a && v[1]*v[2] == b && v[3]*v[4] == c && v[4]*v[5] == d) {
  100. cout<<"! ";
  101. for(auto it : v) {
  102. cout<<it<<" ";
  103. }
  104. break;
  105. }
  106. } while (next_permutation(v.begin(), v.end()));
  107. cout<<endl;
  108. return 0;
  109. }

codeforces 1167B Lost Numbers的更多相关文章

  1. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  2. Codeforces 878 E. Numbers on the blackboard

    Codeforces 878 E. Numbers on the blackboard 解题思路 有一种最优策略是每次选择最后面一个大于等于 \(0\) 的元素进行合并,这样做完以后相当于给这个元素乘 ...

  3. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  4. CodeForces 151B Phone Numbers

     Phone Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  5. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  6. Codeforces 165E Compatible Numbers(二进制+逆序枚举)

    E. Compatible Numbers time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. CodeForces 165E Compatible Numbers(位运算 + 好题)

    wo integers x and y are compatible, if the result of their bitwise "AND" equals zero, that ...

  9. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. redis 如何查看版本

    ./redis-cli -h 127.0.0.1 info | grep 'redis_version' redis-server -v

  2. F4NNIU 整理的 docker-compose 几个常用命令

    F4NNIU 整理的 docker-compose 几个常用命令 up 创建并启动一个容器. 记录一下,如果已经有容器,up 和 start 都可以启动容器,up 可以看到调试窗口,但是 start ...

  3. jquery on事件

    可以给后添加的动态元素绑定事件

  4. js、php判断手机PC

    用于phpcms <script type="text/javascript"> var url = window.location.href; if(/Android ...

  5. 64位linux源码安装mysql

    一:下载mysql http://dev.mysql.com/downloads/mysql/中的Generally Available(GA) Releases标签页,在MySQL Communit ...

  6. wepy —— 组件之间通信

    一.props 1.静态传值 —— 父组件向子组件传递常量数据 // 父组件 <coma fruitName="橘子"></coma> // 子组件 // ...

  7. 07Redis入门指南笔记(主从复制、哨兵)

    现实项目中通常需要若干台Redis服务器的支持: 结构上,单个 Redis 服务器会发生单点故障,而且一台服务器需要承受所有的请求负载.这就需要为数据生成多个副本并分配在不同的服务器上: 容量上,单个 ...

  8. docker + jenkins 自动化部署

    公司书架上有本docker的书籍,正好最近事不多就写个demo来玩一玩. DevOps未死,ContainerOps已到 ContainerOps VS DevOps 避免了复杂的环境,应用之间的相互 ...

  9. 根据User Agent参数的各个字段Mozilla/5.0/4.0-AppleWebKit/Chrome/Safari/Firefox/Opera/MSIE来确定/判断客户端使用什么浏览器

    下面给你一一解答以及给你介绍: //Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/533.21.1 (KHTML, like ...

  10. Springboot2 Logback mybatis 打印sql执行语句

    把这个加入到logback.xml 中就可以打印mysql的日志了 <logger name="jdbc.sqltiming" level="debug" ...