首页 > 其他分享 >Codeforces Round 978(div.2) D1

Codeforces Round 978(div.2) D1

时间:2024-10-30 22:45:24浏览次数:9  
标签:cout int impostor t2 Codeforces long t1 div.2 978

#感觉挺有意思的一道题

题目:

思路:

观察发现对于两个人a,b如果两个人里面没有Impostor那么,你得到的回答是一样的,如果有impostor那么结果不同,那么我们就可以两个两个的询问,先找到2个人里面有impostor然后在找另外一个人来询问就行了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
void solve(){
	int n;cin>>n;
	int a=1,b=2;
	while(1){
		int t1,t2;
		cout<<"? "<<a<<" "<<b<<endl;
		cout.flush();
		cin>>t1;
		cout<<"? "<<b<<" "<<a<<endl;
		cout.flush();
		cin>>t2;
		if(t1!=t2){
			break;
		}
		a+=2;
		b+=2;
		if(b>n){
			cout<<"! "<<n<<endl;
			cout.flush();
			return;
		}
	}
	int t=b+1;
	if(t>n)t%=n;
	int t1,t2;
	cout<<"? "<<t<<" "<<a<<endl;
	cout.flush();
	cin>>t1;
	cout<<"? "<<a<<" "<<t<<endl;
	cout.flush();
	cin>>t2;
	if(t1==t2){
		cout<<"! "<<b<<endl;
		cout.flush();
		return;
	}else{
		cout<<"! "<<a<<endl;
		cout.flush();
		return;
	}
	return;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int _;cin>>_;
	while(_--)solve();
	return 0;
}

标签:cout,int,impostor,t2,Codeforces,long,t1,div.2,978
From: https://blog.csdn.net/2301_77680189/article/details/143375260

相关文章

  • Codeforces Global Round 27,D. Yet Another Real Number Problem 题解
    单调栈+贪心题意:给定一个序列从左往右对于每个索引iii,求出其前缀的数组可以进行任意次以下操作的条件下:选择......
  • Codeforces Round 981 (Div. 3) ABCDE
    CodeforcesRound981(Div.3)ABCDEA.SakurakoandKosuke藕是看样例直接猜了结论......
  • Codeforces Round 982 (Div. 2)
    CodeforcesRound982(Div.2)总结A猜结论,最后的图形的周长都能移成一个长方形的周长,这个长方形就是\(w\)和\(h\)的最大值。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<q......
  • # [Educational Codeforces Round 171](https://codeforces.com/contest/2026)
    EducationalCodeforcesRound171D.SumsofSegments定义四个前缀和:\(s_i=a_1+a_2+\dots+a_i\)\(u_i=s_1+s_2+\dots+s_i\)\(t_i=s(i,i)+s(i,i+1)+\dots+s(i,n)\)\(ts_i=t_1+t_2+\dots+t_i\)\(s_i\)为\(a_i\)的前缀和,\(u_i\)为\(s_i\)的前缀和,\(t_i\)为分块之后第......
  • Codeforces 4 A-D
    题面ABCD难度:红橙橙黄题解A题目大意:判断一个正整数\(w\)能否表示成两个正偶数之和。解题思路:考虑分类讨论\(w\)。对于\(1\)和\(2\),显然为NO;对于\(w\ge3\),考虑将其表示为\(x+2\)。根据题意,若\(x\)为偶数,则答案显然必为YES;否则必然为NO。因为\(......
  • [CodeForces] CF628 题解
    A.TennisTournamentLink-CFLink-Luogu【题目大意】\(n\)个选手进行若干场比赛,胜者保留,败者淘汰。每场比赛为两人。每场比赛每个人需要\(b\)瓶水,裁判需要\(1\)瓶水。每个人参加这些比赛总共需要\(p\)条毛巾。注意:洛谷题面翻译有误!建议看英文版。【解题思路】每场比......
  • Educational Codeforces Round 171 (Rated for Div. 2) 10.28 ABCD题解
    EducationalCodeforcesRound171(RatedforDiv.2)10.28(ABCD)题解A.PerpendicularSegments数学(math)计算几何(geometry)题意:给定一个\(X,Y,K\)。需要求解出二维坐标系中的四个点\(A,B,C,D\),满足:\(0\leqA_x,B_x,C_x,D_x\leqX\),\(0\leqA_y,B_y,C_y,D_y\leqY\)。并......
  • Educational Codeforces Round 171 (Div. 2)
    EducationalCodeforcesRound171(Div.2)A猜结论,两条边的最小值最大时,两条边相等。所以取\(min(x,y)\)为边长的正方形,对角线就是所求。#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>usingnamespacestd;intx,y,k;voidsolve(){......
  • Codeforces Global Round 27
    CodeforcesGlobalRound27总结A将红色的位置\((r,c)\)移走,分为三块来考虑,蓝色的块移动\(m-c\),黄色的块移动\(m*(n-r)\),绿色的块移动\((m-1)*(n-r)\)。#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#in......
  • 2024.10.19 CF2030(Div.2)
    比赛链接Solved:5/8Upsolved:6/8Rank:166E.MEXmizetheScore题意定义一个集合的分数为:将它分成若干个子集,mex和的最大值。(mex从0开始算)给n个数,求所有非空子集的分数之和。\(n\leq2\times10^5\)题解对一个确定的集合,它的划分方式一定是每次分出去一个最长的{0,......