题解:P10440 [JOIST 2024] 环岛旅行 / Island Hopping
a_small_OIer · · 题解
[JOIST 2024] 环岛旅行 / Island Hopping
还是 Ad-hoc 大神。
题意分析
有一个
解法
好水,以至于我一个蒟蒻都能会。
一个非常自然的想法是采用一个类似 DFS 的做法,每次从查询距离编号为
对于每个
这样就实现了在
code
#include <bits/stdc++.h>
//#include "island.h"
#define N 310
using namespace std;
typedef long long LL;
//十年OI一场空,不开long long见祖宗
int ans[N] , a[N];
bool vis[N];
int query(int v, int k);
void answer(int x, int y);
void solve(int n, int L){
vis[1] = true;
for(int i = 1 ; i <= n - 1 ; ++i){
int x = query(1 , i);
vis[x] = true;
for(int j = 1 ; !ans[x] ; ++j){
int y = query(x , j);
if(vis[y])
ans[x] = y;
else
ans[y] = x;
}
}
for(int i = 2 ; i <= n ; ++i)
answer(ans[i] , i);
}