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 ...
随机推荐
- LG5003 跳舞的线 - 乱拐弯 线性DP
问题描述 LG5003 题解 设 \(mx[i][j][0/1]\)代表当前位置.朝向的最大拐弯数,最小同理. 来源为左边和上边. 坑点:起点可能为#. \(\mathrm{Code}\) #incl ...
- Python程序练习题(一)
Python:程序练习题(一) 1.2 整数序列求和.用户输入一个正整数N,计算从1到N(包含1和N)相加之后的结果. 代码如下: n=input("请输入整数N:") sum=0 ...
- nui-app 笔记
https://uniapp.dcloud.io
- vscode源码分析【二】程序的启动逻辑,第一个窗口是如何创建的
上一篇文章:https://www.cnblogs.com/liulun/ (小广告:我做的开源免费的,个人知识管理及自媒体营销工具“想学吗”:https://github.com/xland/xia ...
- 用OC基于链表实现链队列
一.简言 在前面已经用C++介绍过链队列的基本算法,可以去回顾一下https://www.cnblogs.com/XYQ-208910/p/11692065.html.少说多做,还是上手撸代码实践一下 ...
- 《细说PHP》第四版 样章 第23章 自定义PHP接口规范 4
23.2.3 在程序中访问接口 本节再优化userapi.php文件中的代码,并多加一个接口函数store(), 模拟一个表单,通过POST提交数据给它,验证并将数据添加到数据库中,代码如下所示: ...
- IT兄弟连 Java语法教程 数组 数组的初始化
Java语言中数组必须先初始化,然后才可以使用.所谓初始化,就是为数组的数组元素分配内存空间,并为每个数组元素赋初始值. 这时有人会问,能不能只分配内存空间,不赋初始值呢?答案是肯定不行的,一旦为数组 ...
- Leetcode练习题Longest Common Prefix
Question: Longest Common Prefix Write a function to find the longest common prefix string amongst an ...
- gcc 编译安装
wget https://kojipkgs.fedoraproject.org//packages/gcc/7.1.1/1.module_1a179a7b/src/gcc-7.1.1-1.module ...
- 杂牌机搞机之旅最终章————刷入Xposed框架
杂牌机搞机之旅最终章----刷入Xposed框架 recovery移植不成功,没办法,挂载分区好像挂载不上,所以,刷入magisk如果卡在开机屏,只能线刷解决..心累.. 所以,折腾完XPosed框架 ...