# Untitled

unknown
plain_text
5 months ago
1.6 kB
3
Indexable
Never
```The Frog

Input:
2 //testcase
2 // so la
1 10 10 // toa do x,y cua la; ban kinh la
100 100 15
4
0 10 10
20 60 12
30 10 10
70 10 8

Output:
-1
0 2

Code:
#include<iostream>
#define max 1000000
using namespace std;

int n;
int map[205][3];
int visit[205];
int front= -1;
int	rear=-1;
int queue[1000000];

void push(int x){
if(rear == max-1) rear =-1;
rear++;
queue[rear]=x;

}

void pop(){
if(front == max-1) front =-1;
front++;
}

bool IsEmpty(){
return front == rear;
}

void reset(){
for(int i=1; i <= n; i++){
visit[i]=1000000;
}
front =rear =-1;
}

int binh(int x){
int result;
result = x*x;
return result;
}

int calculate(int x, int i){
if((binh(map[i][0]-map[x][0]) + binh(map[i][1]-map[x][1])) <= binh(40 +map[i][2] +map[x][2] )) return 1;
else if((binh(map[i][0]-map[x][0]) + binh(map[i][1]-map[x][1])) > binh(40 +map[x][2] + map[i][2]) && (binh(map[i][0]-map[x][0]) + binh(map[i][1]-map[x][1])) <= binh(90 +map[x][2] + map[i][2])) return 200;
return 1000000;
}

void Try(int j){

push(j);
visit[j]=0;

while(!IsEmpty()){
pop();
int x=queue[front];
for(int i=0; i<n; i++){
if(i!=x){
int t = calculate(x,i);
if(visit[i] > visit[x] + t){
visit[i] = visit[x] + t;
push(i);
}
}
}
}
}

int main(){
freopen("Text.txt", "r", stdin);
int test;
cin >> test;

for(int tc= 1; tc <= test; tc++){
cin >> n; // so la

for(int i=0; i < n; i++){
for(int j= 0; j < 3; j++){
cin >> map[i][j];
}
}
reset();
Try(0);
if(visit[n-1] == 1000000) cout << -1<< endl;
else cout << visit[n-1]/200 <<" " << visit[n-1]%200 << endl;

}
return 0;
}
```