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 ...
随机推荐
- 【51nod1678】lyk与gcd(莫比乌斯反演+枚举因数)
点此看题面 大致题意: 一个长度为\(n\)的数组,实现两种操作:单点修改,给定\(i\)求\(\sum_{j=1}^na_j[gcd(i,j)=1]\). 莫比乌斯反演 考虑推一推询问操作的式子: ...
- SVO 特征对齐代码分析
SVO稀疏图像对齐之后使用特征对齐,即通过地图向当前帧投影,并使用逆向组合光流以稀疏图像对齐的结果为初始值,得到更精确的特征位置. 主要涉及文件: reprojector.cpp matcher.cp ...
- Mac--管理mysql、redis服务的常用命令
##启动MySQL服务 sudo /usr/local/MySQL/support-files/mysql.server start ##停止MySQL服务 sudo /usr/local/mysql ...
- Java连载49-常量格式、package包介绍
一.常量 1.常量的定义:final修饰的实例变量是不可变的,这种变量一般和static联合使用,被称为“常量” 2.常量的语法格式: public static final 类型 常量名 = 值: ...
- 用keras构建自己的网络层 TensorFlow2.0教程
1.构建一个简单的网络层 from __future__ import absolute_import, division, print_function import tensorflow as t ...
- React中useEffect使用
2019-08-24 07:00:00 文摘资讯 阅读数 1364 收藏 博文的原始地址 之前我们已经掌握了useState的使用,在 class 中,我们通过在构造函数中设置 this.s ...
- 分析FAT32内部结构-入门篇-
FAT32(File Allocation Table)是一种32位的FAT文件系统,微软在1996年8月发布. FAT32的数字32是下面会讲到的FAT中每个表项的长度. 磁盘(硬盘)是数据的载体, ...
- Anaconda更新报404:UnavailableInvalidChannel: The channel is not accessible or is invalid.error404
Anaconda更新一直报错,修改为国内镜像也不好使,最终找到了未被屏蔽的镜像. 错误日志: UnavailableInvalidChannel: The channel is not accessi ...
- Linux Ubuntu 16.04 安装步骤+远程环境
简介 Ubantu 16.04 系统是一款比较稳定的linux系统,适合用户使用以及针对一些兼容性的服务搭建. 这里我推荐安装桌面版,用于方便使用. 准备工作 1.准备1个U盘空间5G以上 2.需下载 ...
- Vue修改单个组件的背景颜色
组件默认背景颜色为白色,但工作需要改成黑色,于是研究了一番. 很简单,只需在组件中使用两个钩子函数beforeCreate (),beforeDestroy () 代码如下: beforeCreate ...