当前位置:网站首页>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 .
边栏推荐
- [fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)
- Network security - vulnerabilities and Trojans
- stm32F407-------DMA
- 网络安全-ACL访问控制列表
- 去除网页滚动条方法以及内外边距
- mysql
- Custom components, using NPM packages, global data sharing, subcontracting
- Processing of tree structure data
- Explore the conversion between PX pixels and Pt pounds, mm and MM
- 可視化yolov5格式數據集(labelme json文件)
猜你喜欢

How to deal with cache hot key in redis

stm32F407-------DMA

In the face of difficult SQL requirements, HQL is not afraid
![[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)](/img/e7/915404743d6639ac359bb4e7f7fbb7.jpg)
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)

In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?

详细些介绍如何通过MQTT协议和华为云物联网进行通信

Anna: Beibei, can you draw?

Trial setup and use of idea GoLand development tool

Everything file search tool

Rockchip3399 start auto load driver
随机推荐
浏览器是如何对页面进行渲染的呢?
Hard core observation 547 large neural network may be beginning to become aware?
小程序开发黑马购物商城中遇到的问题
One of the C language practical projects is greedy snake
Introduction to kotlin collaboration
Performance test | script template sorting, tool sorting and result analysis
Query product cases - page rendering data
Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
Asian Games countdown! AI target detection helps host the Asian Games!
2022 financial product revenue ranking
Network security - dynamic routing protocol rip
Swift development learning
ByteDance data Lake integration practice based on Hudi
可视化yolov5格式数据集(labelme json文件)
Analyzing several common string library functions in C language
Network security - the simplest virus
全链路数字化转型下,零售企业如何打开第二增长曲线
es6 filter() 数组过滤方法总结
leetcode961. Find the elements repeated N times in the array with length 2n
可視化yolov5格式數據集(labelme json文件)