当前位置:网站首页>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 .
边栏推荐
- Groovy, "try with resources" construction alternative
- [fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)
- 詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
- File class (check)
- [shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
- How to refresh the opening amount of Oracle ERP
- Modify table structure
- Visualisation de l'ensemble de données au format yolov5 (fichier labelme json)
- Redis:Redis的简单使用
- 网络安全-NAT网络地址转换
猜你喜欢
![[leetcode] 797 and 1189 (basis of graph theory)](/img/2a/9c0a904151a17c2d23dea9ad04dbfe.jpg)
[leetcode] 797 and 1189 (basis of graph theory)

In the face of difficult SQL requirements, HQL is not afraid

What are MySQL locks and classifications

What are the key points often asked in the redis interview

Introduction to kotlin collaboration

Asian Games countdown! AI target detection helps host the Asian Games!

PS去除水印详解

Trial setup and use of idea GoLand development tool

小程序开发的部分功能

Analysis, use and extension of open source API gateway apisex
随机推荐
Storage basic operation
Stm32f407 ------- IIC communication protocol
Ni visa fails after LabVIEW installs the third-party visa software
[AUTOSAR cantp] -2.11-uds diagnostic response frame data segment data padding data filling and data optimization data optimization (Theory + configuration)
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
查询商品案例-页面渲染数据
Niuniu's ball guessing game (dynamic planning + prefix influence)
Huakaiyun | virtual host: IP, subnet mask, gateway, default gateway
Function definition and call, this, strict mode, higher-order function, closure, recursion
网络安全-漏洞与木马
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
How do it students find short-term internships? Which is better, short-term internship or long-term internship?
[camera topic] how to save OTP data in user-defined nodes
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
stm32F407-------DMA
His experience in choosing a startup company or a big Internet company may give you some inspiration
ByteDance data Lake integration practice based on Hudi
Summary of ES6 filter() array filtering methods
Network security - phishing
DDL basic operation