1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <set> #include <vector> using namespace std;
const int INF = ~0u>>1; typedef pair <int,int> P; #define MID(x,y) ((x+y)>>1) #define iabs(x) ((x)>0?(x):-(x)) #define REP(i,a,b) for(int i=(a);i<(b);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define mp make_pair #define print() cout<<"--------"<<endl #define pi 3.14159265358979323846 typedef struct { double x; double y; double z; }air; struct Edge{ int u,v; double d; }ed[50500]; air p[110]; int num; #define EPS 1e-8
int pa[110]; bool cmp(Edge a,Edge b){ return a.d < b.d; }
int find(int x){ return (pa[x] == x) ? x: pa[x] = find(pa[x]); }
double Kruskal(int n) { double total = 0; for(int i = 0;i < n;i++) pa[i] = i; sort(ed,ed + num,cmp); for(int i = 0;i < num;i++) { int ru = find(ed[i].u); int rv = find(ed[i].v); if(ru != rv) { total += ed[i].d; pa[rv] = ru; } } return total; }
int main(){ int T,n; scanf("%d", &T); double D,L; while (T--){ scanf("%lf", &D); scanf("%lf", &L); scanf("%d", &n); double R = D / 2.0; double l,r; for (int i = 0; i < n; i ++){ scanf("%lf %lf", &l, &r); l = l * pi/180.0; r = r * pi/180.0; p[i].x = l; p[i].y = r; } num = 0; double c; for (int i = 0; i < n; i ++){ for (int j = 0; j < n; j ++){ if (i == j) continue; c = sin(p[i].x) * sin(p[j].x) + cos(p[i].x) * cos(p[j].x) * cos(p[i].y - p[j].y); ed[num].u = i; ed[num].v = j; ed[num++].d = fabs(R * acos(c)); } } double ans = Kruskal(n); if (ans - EPS < L) puts("Y"); else puts("N"); } return 0; }
|