【交互题】

目录

1 cf 1167B Lost Numbers

2 cf 1807E Interview

3 cf 1713D Tournament Countdown


1 cf 1167B Lost Numbers

https://codeforces.com/contest/1167/problem/B

代码:

// Problem: B. Lost Numbers
// Contest: Codeforces - Educational Codeforces Round 65 (Rated for Div. 2)
// URL: https://codeforces.com/problemset/problem/1167/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>

using namespace std;
#define int long long

const int N = 2e5+5;

int a[7]={0,4,8,15,16,23,42};
int q1,q2,q3,q4;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cout<<"? 1 2"<<endl;
	fflush(stdout);
	cin>>q1;
	
	cout<<"? 2 3"<<endl;
	fflush(stdout);
	cin>>q2;
	
	cout<<"? 3 4"<<endl;
	fflush(stdout);
	cin>>q3;
	
	cout<<"? 4 5"<<endl;
	fflush(stdout);
	cin>>q4;
	
	int shu[7];
	do{
		if(a[1]*a[2]==q1&&a[2]*a[3]==q2&&a[3]*a[4]==q3&&a[4]*a[5]==q4){
			shu[1]=a[1];
			shu[2]=a[2];
			shu[3]=a[3];
			shu[4]=a[4];
			shu[5]=a[5];
			break;
		}
	}while(next_permutation(a+1,a+6+1));
	shu[6]=(4+8+15+16+23+42)-shu[1]-shu[2]-shu[3]-shu[4]-shu[5];
	cout<<"! ";
	for(int i=1;i<=6;i++){
		cout<<shu[i]<<' ';
	}
	cout<<"\n";
	
	
	return 0;	

}

2 cf 1807E Interview

https://codeforces.com/contest/1807/problem/E

代码:

// Problem: E. Interview
// Contest: Codeforces - Codeforces Round 859 (Div. 4)
// URL: https://codeforces.com/contest/1807/problem/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>

using namespace std;
#define int long long

const int N = 2e5+5;

int n;
int a[N],s[N];

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1;i<=n;i++){
			a[i]=0;
			s[i]=0;
		}
		for(int i=1;i<=n;i++){
			cin>>a[i];
			s[i]=s[i-1]+a[i];
		}
		int l=1,r=n,ans=0;
		while(l<r){
			int mid=(l+r)/2;
			int shu=s[mid]-s[l-1];
			cout<<"? "<<mid-(l-1)<<' ';
			for(int i=l;i<=mid;i++){
				cout<<i<<' ';
			}
			cout<<endl;
			fflush(stdout);
			
			ans=0;
			cin>>ans;
			if(ans==shu){
				l=mid+1;
			}
			else{
				r=mid;
			}
		}
		cout<<"! "<<l<<endl;
	}
	
	return 0;	

}

3 cf 1713D Tournament Countdown

https://codeforces.com/contest/1713/problem/D

代码:

// Problem: D. Tournament Countdown
// Contest: Codeforces - Codeforces Round 812 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1713/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>

using namespace std;
#define int long long

const int N = 2e5+5;

int n;

int query(int a,int b){
	cout<<"? "<<a+1<<' '<<b+1<<endl;
	int res;
	cin>>res;
	return res;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int T;
	cin>>T;
	while(T--){
		cin>>n;
		vector<int> a(1<<n);
		iota(a.begin(),a.end(),0);
		
		while(a.size()>=4){
			vector<int> b;
			for(int i=0;i<a.size();i+=4){
				int x=query(a[i],a[i+2]);
				if(x==0){
					if(query(a[i+1],a[i+3])==1){
						b.push_back(a[i+1]);
					}
					else{
						b.push_back(a[i+3]);
					}
				}
				else if(x==1){
					if(query(a[i],a[i+3])==1){
						b.push_back(a[i]);
					}
					else{
						b.push_back(a[i+3]);
					}
				}
				else{
					if(query(a[i+1],a[i+2])==1){
						b.push_back(a[i+1]);
					}
					else{
						b.push_back(a[i+2]);
					}
				}
			}
			a=b;
		}
		
		if(a.size()==2){
			if(query(a[0],a[1])==1){
				a={a[0]};
			}
			else{
				a={a[1]};
			}
		}
		cout<<"! "<<a[0]+1<<endl;
	}
	

	
	return 0;	

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值