当前位置:网站首页>Cfdiv2 fixed point guessing- (interval answer two points)
Cfdiv2 fixed point guessing- (interval answer two points)
2022-07-03 02:04:00 【Lovely and beautiful girl】
The question :
Is to give you a 1 To n Array of , But among them n+1/2 Secondary exchange , Each number will only be exchanged once , So only one number has not been exchanged . Then you can query 15 Time , One interval at a time , Will return to you the number of this interval from small to large after the order . Now I ask you which number has not been exchanged .
reflection :
At the beginning 15 I know it's two points at a time , But I thought it was dfs Two points , Every recursive judgment . But I feel it's not easy to write . Actually , For dichotomy , You can divide the answer in which range . That is to judge first l To r, If the answer is in here ,r = mid. otherwise l = mid+1. That is, in another interval . This is simply to judge in which range , With theout an answer, better is worse . But how to judge , In fact, for , Number of inputs x, If x stay l To r Inside , That means he changed it for one of them , Then the number in it will appear twice , Otherwise, it would be 0 Time . But which number without exchange will contribute once , So if it's an odd number , Then the answer is this interval .
Code :
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define db double
#define int long long
#define PII pair<int,int >
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int mod = 1e9+7,inf = 1e18;
const int N = 2e5+10,M = 2010;
int T,n,m,k;
int va[N];
int check(int l,int r)
{
cout<<"? "<<l<<" "<<r<<"\n";
cout.flush();
int sum = 0;
for(int i=l;i<=r;i++)
{
int x;
cin>>x;
if(x>=l&&x<=r) sum++;
}
return sum;
}
signed main()
{
cin>>T;
while(T--)
{
cin>>n;
int l = 1,r = n;
while(l<r)
{
int mid = (l+r)/2;
if(check(l,mid)&1) r = mid;
else l = mid+1;
}
cout<<"! "<<l<<"\n";
}
return 0;
}
summary :
Think more , Accumulate experience .
边栏推荐
- 微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
- Groovy, "try with resources" construction alternative
- The technology boss is ready, and the topic of position C is up to you
- Analyzing several common string library functions in C language
- Basic operation of view
- Network security - Trojan horse
- Some functions of applet development
- 创建+注册 子应用_定义路由,全局路由与子路由
- NCTF 2018 part Title WP (1)
- DML Foundation
猜你喜欢
Visual yolov5 format data set (labelme JSON file)
Introduction to kotlin collaboration
Ni visa fails after LabVIEW installs the third-party visa software
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
mysql
Niuniu's ball guessing game (dynamic planning + prefix influence)
Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
可視化yolov5格式數據集(labelme json文件)
微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
随机推荐
Network security - Trojan horse
Storage basic operation
Performance test | script template sorting, tool sorting and result analysis
Anna: Beibei, can you draw?
In the face of difficult SQL requirements, HQL is not afraid
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
String replace space
NCTF 2018 part Title WP (1)
疫情当头,作为Leader如何进行团队的管理?| 社区征文
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
[AUTOSAR cantp] -2.11-uds diagnostic response frame data segment data padding data filling and data optimization data optimization (Theory + configuration)
树形结构数据的处理
Network security - scanning and password explosion 2
机器学习笔记(持续更新中。。。)
Certaines fonctionnalités du développement d'applets
网络安全-破解系统密码
Explore the conversion between PX pixels and Pt pounds, mm and MM
Analysis, use and extension of open source API gateway apisex
Analyzing several common string library functions in C language