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 |
一直wa高手帮忙看看啊..#include<iostream> #include <math.h> #include <algorithm> using namespace std; int casetimes=1; typedef struct point { int x,y; }point; typedef struct arc { double x,y; }arc; bool cmp(arc &a,arc &b) { if(a.x >= b.x) //ÕâÀïÁ½¸öÖµÊÇ·ñ¿ÉÒԱȽÏÒª¿´ÄãµÄ¾ßÌåÇé¿ö£¬×Ü֮˼Ïë¾ÍÊÇÈ·¶¨Á½¸öʱ¼äµÄ´óС¡£ return false; else return true; } void compute(point p[],int n,double d) { int i,j,result=1; double x1,x2; arc a[1000]; for(i=0;i<n;i++) { if(p[i].y>d && d>0 || d<=0 ) { printf("Case %d : -1\n",casetimes++); return; } a[i].x = p[i].x- sqrt(d*d-p[i].y*p[i].y); a[i].y = p[i].x+ sqrt(d*d-p[i].y*p[i].y); } sort(a,a+n,cmp); // for(i=1;i<=n-1;i++) // { // if(a[i-1].y < a[i].x) // result++; // } double pre=a[0].y; result=1; for(i=1;i<n;i++) { if(a[i].x>pre) { result++; pre=a[i].y; } else { if(a[i].y<pre) pre=a[i].y; } } printf("Case %d : %d\n",casetimes++,result); } int main() { int i,j,n=1; int d; char a='1',b='1'; point p[1000]; freopen("test.txt","r",stdin); while(n!=0&& d!=0) { scanf("%d%d",&n,&d); if(n==0 && d ==0) break; for(i=0;i<n;i++) { scanf("%d%d", &p[i].x, &p[i].y); } compute(p,n,d); scanf("%c%c",&a,&b); } fclose(stdin); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator