跳到正文

题解

题解:CF2133C The Nether

LinAB约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年8月26日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 3 分钟
题目
CF2133C

版本

  1. v1当前

[CF2133C] The Nether 题解

分析:

题目要求找到一条访问最多传送门的路径,

因此可以直接进行 nn 次形如:? i n 1 2 ... n-1 n 的查询来得到从 ii 点出发可以到达最多传送门的路径。

将得到的序列进行降序排序,序列的第一位就是可以访问最多传送门的路径的传送门数量(可能是之一),将其压入最多传送门的路径序列。

容易发现,传送门数量为 l (l>1)l \space (l \gt 1) 的路径的起点一定会与不少于一个传送门数量为 l−1l-1 的路径的起点相连,

因此在枚举传送门数量为 ll 时,可以进行形如:? j 2 i j 对于两个传送门是否连通进行查询(其中 ii 是传送门数量为 ll 的路径的起点,jj 是传送门数量为 l−1l-1 的路径的起点)。如果得到的结果是 2,说明这两个传送门相连,可以将 jj 压入最多传送门的路径序列。

如此循环往复,便可以在最多 n−1n-1 次查询后得到完整的最多传送门的路径序列,输出即可。

最多查询 n+(n−1)=2n−1<2nn+(n-1) = 2n-1 \lt 2n 次,可以通过此题。

代码:

C++
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define reg register
#define il inline
using namespace std;
const int N = 5e2+10;
void solve(){
	int n,mxl;
	pair<int,int> l[N];
	vector<int> p;
	memset(l,0,sizeof l);
	cin>>n;
	for(int i=1;i<=n;i++){
		cout<<"? "<<i<<" "<<n<<" ";
		for(int j=1;j<=n;j++) cout<<j<<" ";
		cout<<endl;
		cin>>l[i].first; l[i].second=i;
	}sort(l+1,l+n+1,greater<pair<int,int> >());
//	for(int i=1;i<=n;i++) cout<<l[i].second<<" ";
	mxl=l[1].first; p.emplace_back(l[1].second);
	int cnt=1;
	for(int i=mxl-1;i>0;i--){
		while(l[cnt].first==i+1) cnt++;
		while(l[cnt].first==i){
			cout<<"? "<<p[p.size()-1]<<" 2 "<<p[p.size()-1]<<" "<<l[cnt].second<<endl;
			int tmp; cin>>tmp;
			if(tmp==2){
				p.emplace_back(l[cnt].second);
				break;
			}cnt++;
		}
	}cout<<"! "<<p.size()<<" ";
	for(int pp:p) cout<<pp<<" ";
	cout<<endl;
}
int main(){
	int T; cin>>T;
	while(T--) solve();
	return 0;
}

AC提交记录

原文