当前位置:网站首页>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.
边栏推荐
- 苏世民:25条工作和生活原则
- Everything file search tool
- When the epidemic comes, how to manage the team as a leader| Community essay solicitation
- stm32F407-------DMA
- How to refresh the opening amount of Oracle ERP
- Answers to ten questions about automated testing software testers must see
- Leetcode 183 Customers who never order (2022.07.02)
- Swift开发学习
- 疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
- 网络安全-防火墙
猜你喜欢

Stm32f407 ------- IIC communication protocol

Depth (penetration) selector:: v-deep/deep/ and > > >

One of the C language practical projects is greedy snake

Technology sharing | Frida's powerful ability to realize hook functions

【Camera专题】OTP数据如何保存在自定义节点中

树形结构数据的处理
![[camera topic] complete analysis of camera dtsi](/img/cb/d42589fcf0610600c9dc8c7992d4d7.png)
[camera topic] complete analysis of camera dtsi
![[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)](/img/ac/bf83f319ea787c5abd7ac3fabc9ede.jpg)
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)

In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?

stm32F407-------ADC
随机推荐
Reprint some Qt development experience written by great Xia 6.5
Network security - the simplest virus
网络安全-破解系统密码
mysql
Leetcode(540)——有序数组中的单一元素
Performance test | script template sorting, tool sorting and result analysis
[Yu Yue education] Jiujiang University material analysis and testing technology reference
Leetcode 183 Customers who never order (2022.07.02)
Explore the conversion between PX pixels and Pt pounds, mm and MM
Where is the future of test engineers? Confused to see
网络安全-防火墙
[leetcode] 797 and 1189 (basis of graph theory)
Visualisation de l'ensemble de données au format yolov5 (fichier labelme json)
[Appendix 6 Application of reflection] Application of reflection: dynamic agent
网络安全-ACL访问控制列表
疫情當頭,作為Leader如何進行團隊的管理?| 社區征文
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
Swift开发学习
力扣(LeetCode)183. 从不订购的客户(2022.07.02)
Technology sharing | Frida's powerful ability to realize hook functions