[Luogu] 奶酪
阿新 • • 發佈:2018-05-03
tdi mes double spa ostream math con #define include
https://www.luogu.org/problemnew/show/P3958
連邊bfs / 並查集
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int N = 1010; #define gc getchar() struct Node{ double x, y, z; }E[N]; int n; double h, r; int T;int f[N]; inline int read(){ int x = 0; char c = gc; while(c < ‘0‘ || c > ‘9‘) c = gc; while(c >= ‘0‘ && c <= ‘9‘) x = x * 10 + c - ‘0‘, c = gc; return x; } int getf(int x){ return f[x] == x ? x : f[x] = getf(f[x]); } inline bool calc_dis(int x, inty){ double X1 = E[x].x, Y1 = E[x].y, Z1 = E[x].z; double X2 = E[y].x, Y2 = E[y].y, Z2 = E[y].z; double dis = sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * ((Y1 - Y2)) + (Z1 - Z2) * (Z1 - Z2)); return dis <= r * 2 ? 1 : 0; } inline bool dis_0(int x){ if(abs(E[x].z - 0) <= r) return1; return 0; } inline bool dis_h(int x){ if(abs(E[x].z - h) <= r) return 1; return 0; } int main() { T = read(); while(T --){ n = read(); scanf("%lf%lf", &h, &r); for(int i = 1; i <= n; i ++) f[i] = i; for(int i = 1; i <= n; i ++) scanf("%lf%lf%lf", &E[i].x, &E[i].y, &E[i].z); for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ if(i != j && calc_dis(i, j)){ f[getf(i)] = f[getf(j)]; } } } bool flag = 1; for(int i = 1; i <= n && flag; i ++){ for(int j = 1; j <= n && flag; j ++){ if(dis_0(i) && dis_h(j) && getf(i) == getf(j)){ puts("Yes"); flag = 0; } } } if(flag) puts("No"); } return 0; } /* 1 2 5 1 0 0 1 0 0 4 */
[Luogu] 奶酪