# 題目

CHSH OJ c004 兵長砍猴

# 解題思路

目前沒東西...

# 程式碼

#include <bits/stdc++.h>
using namespace std;
#define N 5005
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,x0,y0,l0;
        cin>>n>>x0>>y0>>l0;
        vector<vector<int>> v;
        bool visit[N]={0},c=1;
        for(int i=0,tx,ty,tl;i<n;i++){
            cin>>tx>>ty>>tl;
            v.push_back({tx,ty,tl});
        }
        queue<vector<int>> q;
        q.push({x0,y0,l0,0});
        while(!q.empty()){
            vector<int> qu=q.front();
            q.pop();
            if(qu[2]==0){
                cout<<qu[3]<<"\n";
                c=0;
                break;
            }
            for(int i=0;i<n;i++){
                if(!visit[i] && abs(qu[0] - v[i][0])+abs(qu[1] - v[i][1]) <= qu[2]){
                    q.push({v[i][0],v[i][1],v[i][2],qu[3]+1});
                    visit[i]=1;
                }
            }
        }
        if(c) cout<<"-1\n";
    }
}
更新於 閱讀次數 次