Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
咋回事实在是撑不住了,在这里问下 我是这样想的, 先把所有island排序,然后从左往右, 先放一个能覆盖第一个island的最右边的rader,然后看第二个能不能被覆盖,如果能,就算了, 否则再放能覆盖第二个island的最右边的rader,。。。一直下去 但是为何就wa,我觉得和大家用得那个分段区间也差不多。 为啥?? #include<stdio.h> #include<math.h> int main(){ int n; float d; int i,j, k; int ct ; int step= 0; float a[1000]; float x[1000]; float y[1000]; float tmp; bool flag = true; while(scanf("%d %f", &n, &d)!=EOF && (n!=0 ||d!=0) ){ flag = true; for(i=0; i<n; i++){ scanf("%f %f", &x[i], &y[i]); if(y[i] > d) flag = false; } if(flag == false || d<=0){ printf("Case %d: %d\n", step, -1); continue; } for(i=0; i<n ; i++) for(j=i+1; j<n; j++) if(x[i] > x[j]){ tmp = x[j]; x[j] = x[i]; x[i] = tmp; tmp = y[j]; y[j] = y[i]; y[i] = tmp; } ct = 0; a[ct++] = sqrt(d*d-y[0]*y[0]) + x[0]; for(i=1; i<n; i++){ if((x[i]-a[i-1])*(x[i]-a[i-1])+y[i]*y[i] > d*d){ a[ct++] = sqrt(d*d-y[i]*y[i]) + x[i]; } } printf("Case %d: %d\n", ++step, ct); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator