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 |
plz!!!!!!!!XDI don't know why I always get WA. Someone plzzz help me! #include <iostream> #include <math.h> #include <stdio.h> #include <stdlib.h> using namespace std; typedef struct{ double left; double right; }INTERVAL; int compare(const void* a, const void* b){ INTERVAL* i1= (INTERVAL*) a; INTERVAL* i2= (INTERVAL*) b; return (*i1).left-(*i2).left; } int main(){ int x,y,r; int numCase; double x0,r0; bool error=false; int i,t,caseNow; INTERVAL interval[1001]; int size=0; int result; caseNow=0; while (1){ size=0; result=1; caseNow++; error=false; cin >>numCase>>r; if (!numCase && !r) return 0; if(r<=0) error=true; for (i=0;i<numCase;i++){ cin >>x>>y; r0=sqrt(r*r-y*y); if(r<y) error=true; if(y<0) error=true; r0=x-r0; interval[i].left=r0-r; interval[i].right=r0+r; //cout <<interval[i].left<<" "<<interval[i].right<<endl; size++; } if(error){ cout <<"Case "<<caseNow<<": -1"<<endl; }else{ qsort(interval,numCase,sizeof(INTERVAL),compare); //for (i=0;i<numCase;i++) cout <<interval[i].left<<" "<<interval[i].right<<endl; for(i=1; i<numCase;i++){ // cout <<"result"<<result<<endl; // cout <<interval[i].left<<" "<<interval[i-1].right<<endl; // cout <<((interval[i].left) > (interval[i-1].right))<<endl; if ((interval[i].left) > (interval[i-1].right)) result++; } cout <<"Case "<<caseNow<<": "<<result<<endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator