当前位置:网站首页>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 .
边栏推荐
- Answers to ten questions about automated testing software testers must see
- 函数的定义和调用、this、严格模式、高阶函数、闭包、递归
- Take you ten days to easily complete the go micro service series (II)
- 网络安全-DNS欺骗与钓鱼网站
- 网络安全-动态路由协议RIP
- Huakaiyun | virtual host: IP, subnet mask, gateway, default gateway
- 詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
- Comment le chef de file gère - t - il l'équipe en cas d'épidémie? Contributions communautaires
- Visual yolov5 format data set (labelme JSON file)
- Storage basic operation
猜你喜欢

詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信

Network security - vulnerabilities and Trojans

Custom components, using NPM packages, global data sharing, subcontracting

Query product cases - page rendering data
![[camera topic] complete analysis of camera dtsi](/img/cb/d42589fcf0610600c9dc8c7992d4d7.png)
[camera topic] complete analysis of camera dtsi

easyExcel

LabVIEW安装第三方VISA软件后NI VISA失效
![[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)](/img/68/65b8c0530cfdc92ba4f583b0162544.gif)
[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)

Smart management of Green Cities: Digital twin underground integrated pipe gallery platform

Trial setup and use of idea GoLand development tool
随机推荐
Anna: Beibei, can you draw?
小程序开发的部分功能
Network security - man in the middle attack
The technology boss is ready, and the topic of position C is up to you
Smart management of Green Cities: Digital twin underground integrated pipe gallery platform
What are MySQL locks and classifications
Leetcode 183 Customers who never order (2022.07.02)
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
Hard core observation 547 large neural network may be beginning to become aware?
LabVIEW安装第三方VISA软件后NI VISA失效
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
苏世民:25条工作和生活原则
Visual yolov5 format data set (labelme JSON file)
创建+注册 子应用_定义路由,全局路由与子路由
Network security - scan
全链路数字化转型下,零售企业如何打开第二增长曲线
¢ growth path and experience sharing of getting an offer
In the face of difficult SQL requirements, HQL is not afraid
His experience in choosing a startup company or a big Internet company may give you some inspiration