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 ...
随机推荐
- 一篇文章弄懂flex布局
壹 ❀ 引 谈到flex布局,我不知道有多少人跟我一样,在本能的想到justify-content:center与align-items:center两条属性之后,除此之外的其它属性居然显得格外陌生 ...
- CSS修改选中文本颜色与背景色
壹 ❀ 引 在做博客美化的时候,想着去修改文本选中的背景色,因为网页默认是蓝底白字,看着与自己博客整体配色不太搭配,所以想着去改改. 贰 ❀ ::selection 解决方案其实很简单,使用css ...
- 正则表达式中的.*?和python中re.S参数的详解
本章的内容主要是为讲解在正则表达式中常用的.*?和re.S! 在正则表达式中有贪婪匹配和最小匹配:如下为贪婪匹配(.*) import re match = re.search(r'PY.*', 'P ...
- oracle 中 to_date 函数的用法
常犯错的使用方法. to_date('2019-08-12 22:05:','yyyy-MM-dd HH24:mm:ss') Oracle中会引起错误:"ORA 01810 格式代码出现两次 ...
- vs未能正确加载CSharpPackage包,未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包
VS2017打开项目时提示未能正确加载CSharpPackage包, 可以使用 devenv命令工具来解决,操作如下 打开vs2017开发人员命令提示符(请使用管理员身份运行),如图 敲入 deve ...
- Json互相序列化对象
using System.ServiceModel; using System.ServiceModel.Web; using System.Runtime.Serialization.Json; u ...
- 【hexo+github搭建myblog】bash: npm: command not found 问题,疑似解决!关键词:NPM全局安装路径
情况:打算用hexo+github搭建个人博客 1. hexo搭建,参考博文如下,非常感谢: Hexo+Github博客搭建完全教程 hexo从零开始到搭建完整 问题: 在最基本的安装步骤 (参考链接 ...
- css布局技巧
CSS用户界面样式 鼠标样式currsor li{ cursor:pointer: } 设置或检索在对象上移动鼠标指针采用何种系统预定义的光标形状 属性值 描述 default 默认 pointer ...
- CSTC-2017-Web-writeup
0x01 前言 这一次的比赛web题只做出来3个,也是菜的抠脚.. 0x02 web-签到题 php弱类型 查看源码,发现是代码审计,要求用户名必须为字母,密码必须为数字,登陆页面可以用开头为0 ...
- iOS中session和cookie的使用
获取session的方法: #pragma mark - 获取session -(NSString *)getsession{ NSHTTPCookieStorage *cookieStorage = ...