题解:P14002 [eJOI 2025] Navigation
Iruka_Okazaki · · 题解
先考虑一颗树的情况。
我们设
然后你发现其实
但是放到仙人掌上你就会发现你走到最后会发现你两边都是
然后直接走到第一个
但是这个是在我们假设我们是从外面来的,而不是从环上开始的,不然环的开头就不可能在外面还有一个
std::pair<int, int> navigate(int currColor, std::vector<int> adjColors)
{
int col = currColor;
vector<int> &e = adjColors;
int cnt[4] = {0,0,0,0},pos[4] = {0,0,0,0};
for(int i = 0;i < e.size();i++)cnt[e[i]]++,pos[e[i]] = i;
if(cnt[3])return {cnt[2] > 1 ? 2 : 0,pos[3]};
if(cnt[0])return {col == 3 ? 1 : 2,pos[0]};
if(cnt[2] == 1)return {1,pos[2]};
if(cnt[2] == 2)
{
if(col == 0 || col == 2)return {3,pos[2]};
if(col == 3)
{
int ncol = 0;
for(int i = 0;i < e.size();i++)if(e[i] == 2){ncol = i;break;}
return {1,ncol};
}
}
return {-1,-1};
}