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 二分 + 交互(求树的直径)的更多相关文章

  1. 【CF1146】Forethought Future Cup - Elimination Round

    Forethought Future Cup - Elimination Round 窝也不知道这是个啥比赛QwQ A. Love "A" 给你一个串,你可以删去若干个元素,使得最 ...

  2. CF1146 Forethought Future Cup Elimination Round Tutorial

    CF1146 Forethought Future Cup Elimination Round Tutorial 叮,守夜冠军卡 https://codeforces.com/blog/entry/6 ...

  3. Codeforces Forethought Future Cup Elimination Round 选做

    1146C Tree Diameter 题意 交互题.有一棵 \(n(n\le 100)\) 个点的树,你可以进行不超过 \(9\) 次询问,每次询问两个点集中两个不在同一点集的点的最大距离.求树的直 ...

  4. Forethought Future Cup - Elimination Round

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long char getc(){char c=get ...

  5. Forethought Future Cup - Elimination Round D 贡献 + 推公式 + 最短路 + 贪心

    https://codeforces.com/contest/1146/problem/D 题意 有一只青蛙,一开始在0位置上,每次可以向前跳a,或者向后跳b,定义\(f(x)\)为青蛙在不跳出区间[ ...

  6. 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 ...

  7. Forethought Future Cup - Final Round (Onsite Finalists Only) C. Thanos Nim 题解(博弈+思维)

    题目链接 题目大意 给你n堆石子(n为偶数),两个人玩游戏,每次选取n/2堆不为0的石子,然后从这n/2堆石子中丢掉一些石子(每一堆丢弃的石子数量可以不一样,但不能为0),若这次操作中没有n/2堆不为 ...

  8. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  9. 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 ...

随机推荐

  1. import和from...import

    目录 一.import 模块名 二.from 模块名 import 具体的功能 三.import和from...import...的异同 一般使用import和from...import...导入模块 ...

  2. Android常用adb命令总结(一)

    ADB是android sdk里的一个工具,用这个工具可以直接操作管理android模拟器或者真实的andriod设备. ADB是一个客户端-服务器端程序,其中客户端是你用来操作的电脑,服务器端是an ...

  3. 使用ZeroClipboard操作剪切板

    一.ZeroClipboard下载地址 点击下载 二.添加js引用 <script src="../Assets/js/jquery-1.8.3.min.js">< ...

  4. C# - VS2019通过重写pictureBox实现简单的桌面截图功能

    前言 通过创建客制化组件(继承pictureBox),新增属性和构造方法,实现屏幕截图时需要用到的功能点.再通过监控鼠标按下.移动和释放,来获取起始点区域.最后通过操作BMP图像,实现截图的新增.修改 ...

  5. python bin文件处理

    参考: https://blog.csdn.net/and_then111/article/details/86744938 https://blog.csdn.net/zw515370851/art ...

  6. Python 使用 PyMysql、DBUtils 创建连接池,提升性能

    转自:https://blog.csdn.net/weixin_41287692/article/details/83413775 Python 编程中可以使用 PyMysql 进行数据库的连接及诸如 ...

  7. Winform中设置ZedGraph的X轴的刻度根据曲线获取

    场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  8. C#窗体间常用的几种传值方式、以及委托与事件的详细介绍

    窗体间的传值,最好使用委托方式传值,开始之前,我们先来说一下委托与事件的关系. 委托:是一个类. 事件:是委托类型的一个特殊实例,只能在类的内部触发执行. 首先创建2个窗体,这里我们以form1为发送 ...

  9. FCC---Make Motion More Natural Using a Bezier Curve--- juggling movement

    This challenge animates an element to replicate the movement of a ball being juggled. Prior challeng ...

  10. 官宣:腾讯WeTest明星工具-PerfDog面向全球发布!

    导读 PerfDog(官网:perfdog.qq.com)作为移动全平台性能测试分析专业工具,在腾讯内部研发测试工具商店-WeTest Store上线后服务了近2000+名开发者,其中<王者荣耀 ...