Forethought Future Cup - Elimination Round C 二分 + 交互(求树的直径)
https://codeforces.com/contest/1146/problem/C
题意
一颗大小为n的树,每次可以询问两个集合,返回两个集合中的点的最大距离,9次询问之内得出树的直径
题解
- 求树的直径:先找到一个点a,找到离他最远的一个点b,最后找到距离b最远的点c,b和c之间的距离就是树的直径
- 先询问离1最远的距离,然后二分找到这个点a,然后询问a的最远距离
代码
#include<bits/stdc++.h>
#define fk fflush(stdout)
using namespace std;
int T,x;
int qy(int l,int r){
printf("1 %d 1",r-l+1);
for(int i=l;i<=r;i++)printf(" %d",i);
printf("\n");
fk;
int x;
scanf("%d",&x);
return x;
}
int main(){
scanf("%d",&T);
while(T--){
int ans,n;
scanf("%d",&n);
printf("1 %d",n-1);
for(int i=1;i<=n;i++)printf(" %d",i);
printf("\n");
fk;
scanf("%d",&x);
int l=2,r=n,mid;
while(l<r){
mid=(l+r)/2;
if(qy(l,mid)<x)l=mid+1;
else r=mid;
}
printf("1 %d",n-1);
printf(" %d",l);
for(int i=1;i<=n;i++)if(l!=i)printf(" %d",i);
printf("\n");
fk;
scanf("%d",&ans);
printf("-1 %d\n",ans);
fk;
}
}
Forethought Future Cup - Elimination Round C 二分 + 交互(求树的直径)的更多相关文章
- 【CF1146】Forethought Future Cup - Elimination Round
Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...
- CF1146 Forethought Future Cup Elimination Round Tutorial
CF1146 Forethought Future Cup Elimination Round Tutorial 叮,守夜冠军卡 https://codeforces.com/blog/entry/6 ...
- Codeforces Forethought Future Cup Elimination Round 选做
1146C Tree Diameter 题意 交互题.有一棵 \(n(n\le 100)\) 个点的树,你可以进行不超过 \(9\) 次询问,每次询问两个点集中两个不在同一点集的点的最大距离.求树的直 ...
- Forethought Future Cup - Elimination Round
A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long char getc(){char c=get ...
- Forethought Future Cup - Elimination Round D 贡献 + 推公式 + 最短路 + 贪心
https://codeforces.com/contest/1146/problem/D 题意 有一只青蛙,一开始在0位置上,每次可以向前跳a,或者向后跳b,定义\(f(x)\)为青蛙在不跳出区间[ ...
- Codeforces Round #557 Div. 1 based on Forethought Future Cup - Final Round
A:开场就读错题.读对了之后也没啥好说的. #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- Forethought Future Cup - Final Round (Onsite Finalists Only) C. Thanos Nim 题解(博弈+思维)
题目链接 题目大意 给你n堆石子(n为偶数),两个人玩游戏,每次选取n/2堆不为0的石子,然后从这n/2堆石子中丢掉一些石子(每一堆丢弃的石子数量可以不一样,但不能为0),若这次操作中没有n/2堆不为 ...
- codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法
A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)
A. Is it rated? time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
随机推荐
- Linux 学习记录二(文件的打包压缩).
和 window不同,在Linux压缩文件需要注意的是,压缩后的文件会把源文件给替代,无论是gzip.bzip2.xz 均不支持压缩目录,要达到压缩目录的目的,需要用到tar指令. gzip 压缩 ...
- 三、动态SQL
动态SQL MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑. 动态SQL的元素 元素 作用 备注 if 判断语句 单条件分支判断 choose.whe ...
- 解决 layui 弹出层(弹框)一闪而过就消失的问题 (转载)
转载: 原文链接:https://blog.csdn.net/qq_20594019/article/details/83956532 本人遇到问题:使用layer.open()弹出页面层,出现弹框闪 ...
- keras EfficientNet介绍,在ImageNet任务上涨点明显 | keras efficientnet introduction
本文首发于个人博客https://kezunlin.me/post/88fbc049/,欢迎阅读最新内容! keras efficientnet introduction Guide About Ef ...
- 【面试】Java中sleep和wait的区别
1.sleep方法是Thread类的静态方法: wait方法是Object类的成员方法 2.sleep方法使当前线程暂停执行指定的时间,让出cpu给其他线程,但是它的监控状态依然保持着,当指定的时间到 ...
- 英语阅读——The confusing pursuit of beauty
这篇文章是<新视野大学英语>第四册的第二单元的文章,很好的一篇议论文,读起来也很有意思. 1 If you're a man, at some point a woman will ask ...
- StringBuilder修改字符串内容,增,删,改,插
package seday01;/** * 字符串不变对象特性只针对字符串重用,并没有考虑修改操作的性能.因此String不适合频繁修改内容. * 若有频繁修改操作,使用StringBuilder来完 ...
- idea使用心得
简单的概括如下: IntelliJ系中的 Project 相当于Eclipse系中的 Workspace : IntelliJ系中的 Module 相当于Eclipse系中的 Project ...
- opencv::基于颜色跟踪检测
基于颜色跟踪 inRange过滤 形态学操作提取 轮廓查找 外接矩形获取 位置标定
- SoapUI、Postman测试WebService
之前装了SoapUI,最近装了Postman,分别用它们测试了WebService,下面为用法. 测试的在线WebService(数据来源于中国气象局)Endpoint: http://www.web ...