当前位置:网站首页>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 .
边栏推荐
- Where is the future of test engineers? Confused to see
- 单词单词单词
- Button button adaptive size of wechat applet
- Everything file search tool
- Network security NAT network address translation
- 【Camera专题】HAL层-addChannel和startChannel简析
- [error record] navigator operation requested with a context that does not include a naviga
- Visual yolov5 format data set (labelme JSON file)
- In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
- 网络安全-NAT网络地址转换
猜你喜欢

Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly

Hard core observation 547 large neural network may be beginning to become aware?

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

网络安全-漏洞与木马

¢ growth path and experience sharing of getting an offer

stm32F407-------ADC

Network security - vulnerabilities and Trojans

Trial setup and use of idea GoLand development tool

What are the key points often asked in the redis interview

Anna: Beibei, can you draw?
随机推荐
CFdiv2-Fixed Point Guessing-(区间答案二分)
How to deal with cache hot key in redis
Method of removing webpage scroll bar and inner and outer margins
Network security - scanning and password explosion 2
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
String replace space
[camera topic] how to save OTP data in user-defined nodes
[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)
深度(穿透)选择器 ::v-deep/deep/及 > > >
树形结构数据的处理
詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
全链路数字化转型下,零售企业如何打开第二增长曲线
Deep learning notes (constantly updating...)
How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
What are the key points often asked in the redis interview
File class (add / delete)
深度学习笔记(持续更新中。。。)
Socket programming
[Appendix 6 Application of reflection] Application of reflection: dynamic agent
PS remove watermark details