Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 725 Accepted Submission(s): 307
node
1 /* 2 ID: asif 3 LANG: C++ 4 TASK: test 5 */ 6 //# pragma comment(linker, "/STACK:102400000,102400000") 7 # include<iostream> 8 # include<cstdio> 9 # include<cstdlib> 10 # include<cstring> 11 # include<algorithm> 12 # include<cctype> 13 # include<cmath> 14 # include<string> 15 # include<set> 16 # include<map> 17 # include<stack> 18 # include<queue> 19 # include<vector> 20 # include<numeric> 21 using namespace std; 22 const int maxn=111; 23 const double inf=0.000001; 24 const int INF=~0U>>1; 25 const int mod=1000000007; 26 # define PI (acos(0)*2.0) 27 # define lson l,m,rt<<1 28 # define rson m+1,r,rt<<1 | 1 29 # define PS printf("\n") 30 # define S(n) scanf("%d",&n) 31 # define P(n) printf("%d\n",n) 32 # define Ps(n) printf(" %d",(n)) 33 # define SB(n) scanf("%lld",&n) 34 # define PB(n) printf("%lld\n",n) 35 # define PBs(n) printf(" %lld",n) 36 # define SD(n) scanf("%lf",&n) 37 # define PD(n) printf("%.3lf\n",n) 38 # define Sstr(s) scanf("%s",s) 39 # define Pstr(s) printf("%s\n",s) 40 # define S0(a) memset(a,0,sizeof(a)) 41 # define S1(a) memset(a,-1,sizeof(a)) 42 # define pi 3.14159265358979323846 43 typedef long long ll; 44 int n,f[maxn],m; 45 struct node 46 { 47 int x; 48 int y; 49 double v; 50 }; 51 node edge[maxn*maxn]; 52 int equal(double x,double y) 53 { 54 if(x-y>=-inf&&x-y<=inf) 55 return 0; 56 else if(x-y>inf) 57 return 1; 58 return -1; 59 } 60 double rad(double d) 61 { 62 return d * pi / 180.0; 63 } 64 double getDistance(double longitude1, double latitude1, 65 double longitude2, double latitude2,double EARTH_RADIUS) //網上找的求球上兩點距離的函數模板 66 { 67 double Lat1 = rad(latitude1); 68 double Lat2 = rad(latitude2); 69 double a = Lat1 - Lat2; 70 double b = rad(longitude1) - rad(longitude2); 71 double s = 2 * asin(sqrt(pow(sin(a / 2), 2) 72 + cos(Lat1) * cos(Lat2) 73 * pow(sin(b / 2), 2))); 74 s = s * EARTH_RADIUS; 75 return s; 76 } 77 void init() 78 { 79 for(int i=0;i<=n;i++) 80 f[i]=i; 81 } 82 bool cmp(node t1,node t2) 83 { 84 return t1.v<t2.v; 85 } 86 int find(int x) 87 { 88 if(x==f[x]) 89 return x; 90 return find(f[x]); 91 } 92 void unin(int x,int y) 93 { 94 x=find(x); 95 y=find(y); 96 if(x!=y) 97 f[x]=y; 98 } 99 double kruskal() //kruskal算法求最小生成樹 100 { 101 int num=0; 102 double sum=0; 103 for(int i=0;i<m;i++) 104 { 105 int u=edge[i].x,v=edge[i].y; 106 double w=edge[i].v; 107 if(find(u)!=find(v)) 108 { 109 num++; 110 sum+=w; 111 unin(u,v); 112 } 113 if(num>=n-1) 114 break; 115 } 116 return sum; 117 } 118 int main() 119 { 120 //freopen("input.in", "r", stdin); 121 //freopen("output.out", "w", stdout); 122 int T; 123 S(T); 124 while(T--) 125 { 126 double D,L,x[111],y[111]; 127 scanf("%lf%lf%d",&D,&L,&n); 128 m=0; 129 init(); 130 for(int i=0;i<n;i++) 131 scanf("%lf%lf",&x[i],&y[i]); 132 for(int i=0;i<n-1;i++) 133 { 134 for(int j=i+1;j<n;j++) 135 { 136 edge[m].v=getDistance(y[i],x[i],y[j],x[j],D/2); 137 edge[m].x=i; 138 edge[m].y=j; 139 m++; 140 } 141 } 142 sort(edge,edge+m,cmp); 143 double ans=kruskal(); 144 //PD(ans); 145 if(ans<=L) 146 puts("Y"); 147 else 148 puts("N"); 149 } 150 return 0; 151 }