当前位置:网站首页>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.
边栏推荐
- 创建+注册 子应用_定义路由,全局路由与子路由
- How to refresh the opening amount of Oracle ERP
- [leetcode] 797 and 1189 (basis of graph theory)
- Basic operation of view
- Ni visa fails after LabVIEW installs the third-party visa software
- [Appendix 6 Application of reflection] Application of reflection: dynamic agent
- Anna: Beibei, can you draw?
- Types of map key and object key
- Asian Games countdown! AI target detection helps host the Asian Games!
- 小程序開發的部分功能
猜你喜欢
Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
自定义组件、使用npm包、全局数据共享、分包
[data mining] task 2: mimic-iii data processing of medical database
小程序開發的部分功能
How can retail enterprises open the second growth curve under the full link digital transformation
深度(穿透)选择器 ::v-deep/deep/及 > > >
Some functions of applet development
可視化yolov5格式數據集(labelme json文件)
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
Ni visa fails after LabVIEW installs the third-party visa software
随机推荐
Sweet talk generator, regular greeting email machine... Open source programmers pay too much for this Valentine's day
Network security - scanning and password explosion 2
Caused by: com. fasterxml. jackson. databind. exc.MismatchedInputException: Cannot construct instance o
PS remove watermark details
机器学习笔记(持续更新中。。。)
Trial setup and use of idea GoLand development tool
The technology boss is ready, and the topic of position C is up to you
转载收录6.5大侠写的部分Qt开发经验
Hard core observation 547 large neural network may be beginning to become aware?
Niuniu's ball guessing game (dynamic planning + prefix influence)
[shutter] top navigation bar implementation (scaffold | defaulttabcontroller | tabbar | tab | tabbarview)
Network security - man in the middle attack
Reprint some Qt development experience written by great Xia 6.5
Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
MySQL学习03
¢ growth path and experience sharing of getting an offer
File class (check)
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
"Jetpack - livedata parsing"
Missing library while loading shared libraries: libisl so. 15: cannot open shared object file: No such file