当前位置:网站首页>Cfdiv2 Fixed Point Guessing - (2 points for Interval answer)
Cfdiv2 Fixed Point Guessing - (2 points for Interval answer)
2022-07-03 02:04:00 【Jolie fille.】
Titre:
C'est juste pour toi1ÀnTableau de,Mais ça s'est passén+1/2Sous - échange,Chaque numéro n'est échangé qu'une seule fois,Donc un seul nombre n'a pas été échangé.Alors vous pouvez demander15Une fois,Un intervalle à la fois,Vous renvoie le nombre de cet intervalle de petit à grand après l'arrangement.Maintenant, demandez - vous quel nombre n'a pas été échangé.
Penser:
J'ai commencé à voir15Je savais que c'était deux points,Mais je pensais que oui.dfsDeux points,Chaque jugement récursif.Mais je ne me sens pas très bien pour écrire.En fait,Pour deux points,Vous pouvez diviser la réponse en deux parties dans quelle plage.C'est - à - dire juger d'abordlÀr,Si la réponse est là,r = mid.Sinonl = mid+1.C'est - à - dire dans l'autre section.C'est un simple jugement dans quelle section,Il n'y a pas de réponse, mieux c'est, pire c'est.Mais comment juger,En fait,,Nombre d'entréesx,SixInlÀrÀ l'intérieur,Ça veut dire qu'il l'a échangé contre,Alors les nombres apparaîtront deux fois,Sinon, c'est0Une fois.Mais quel nombre sans échange contribue une fois,Donc si c'est un nombre impair,Alors la réponse est cette section.
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;
}
Résumé:
Réfléchis.,Accumuler de l'expérience.
边栏推荐
- Basic operation of view
- 小程序开发黑马购物商城中遇到的问题
- Network security - scan
- 浏览器是如何对页面进行渲染的呢?
- Anna: Beibei, can you draw?
- A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
- Groovy, "try with resources" construction alternative
- Swift开发学习
- 【Camera专题】HAL层-addChannel和startChannel简析
- stm32F407-------ADC
猜你喜欢

stm32F407-------DMA
![[data mining] task 2: mimic-iii data processing of medical database](/img/ad/4e7b253d60b29351e3ef252ee5230f.png)
[data mining] task 2: mimic-iii data processing of medical database

《上市风云》荐书——唯勇气最可贵

ByteDance data Lake integration practice based on Hudi

Redis: simple use of redis

PS remove watermark details

stm32F407-------IIC通讯协议

Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol

技术大佬准备就绪,话题C位由你决定

Learn BeanShell before you dare to say you know JMeter
随机推荐
【Camera专题】OTP数据如何保存在自定义节点中
stm32F407-------DMA
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
创建+注册 子应用_定义路由,全局路由与子路由
502 (bad gateway) causes and Solutions
Storage basic operation
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
How do browsers render pages?
Network security - Trojan horse
机器学习笔记(持续更新中。。。)
Custom components, using NPM packages, global data sharing, subcontracting
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
苏世民:25条工作和生活原则
Rockchip3399 start auto load driver
Some functions of applet development
Network security - scanning and password explosion 2
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
Leetcode 183 Customers who never order (2022.07.02)
stm32F407-------IIC通讯协议
网络安全-中间人攻击