codeforces 810 D . Glad to see you!
来源:互联网 发布:类似ninjame的软件 编辑:程序博客网 时间:2024/06/08 20:41
D. Glad to see you!
题意:
题意往往是最难的对于弱鸡来说。
简化题意如下:
有n个数字1到n,现在一个人选了k个,现在让你从k个中找出两个数字,找的方法是:询问!这便是交互问题,通过询问的方式:询问三个数字1 x y,1代表问,x、y代表你想问的两个数字,另一个人会回答真正的两个数字离x、y哪一个数字最近,离x近或者两个一样近是TAK,否则是NIE。最后输出答案2 x y。
思路:
我们知道对一个数字在一个非递减区间查找很简单,二分既可,那么两个数字查找是否可以?不妨先对一个数字进行确定,那么另外的一个数字无非两个区间,直接判断即可。
对一个数字查找的时候,因为是二分借用询问的方式,对于二分的区间
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n,k;int query(int l,int r){ if(l < 1 || r > n) return false; string re; cout<<1<<" "<<l<<" "<<r<<endl; cin>>re; return re == "TAK";}int get(int l,int r){ if(l > r) return false; while(l < r) { int mid = (l+r)>>1; if(query(mid,mid+1)) r = mid; else l = mid + 1; } return l;}int main(){// freopen("in.txt","r",stdin); cin>>n>>k; int x,y; x = get(1,n); y = get(1,x-1); if(!query(y,x)) y = get(x+1,n); cout<<2<<" "<<x<<" "<<y<<endl; return 0;}
阅读全文
0 0
- codeforces 810 D . Glad to see you!
- Codeforces Round #415 (Div. 2) D. Glad to see you! 二分, 交互
- [二分 交互] Codeforces 809B Round #415 (Div. 1) B. Glad to see you!
- [交互题][二分]Codeforces#415 (Div. 1) 809B. Glad to see you!
- Nice to see you, Scala
- To see the people you want to see
- 数组nice to see you again
- See you~
- See you~
- 【See you】
- glad......
- joe to see see
- see you later,magic
- hd 1892 See you~
- I see you.
- See you, Hadoop
- hdu 1892 See you~
- SEE YOU,GRADE TWO
- Nginx配置虚拟主机
- 跟着姜少学Java基础编程之四:运算符
- POJ 3352 浅谈边双连通分量缩点
- UI系统 UGUI-RectTransform
- python记录日志
- codeforces 810 D . Glad to see you!
- bzoj3876 支线剧情【上下界最小费用可行流】
- spring boot 使用总结
- 【LeetCode】C# 22、Generate Parentheses
- 计算机视觉opencv的牛人博客和代码汇总-多学习学习
- Stm32-SWD下载调试配置
- 了解索引器、密封类、扩展方法等
- 数据结构-杂记--选择排序
- Mybatis中的insert获取自增主键的值