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 |
建議:d可以是小數,座標都是整數。以double儲存為佳附上AC的code #include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> using namespace std; struct position{ float x,y; }arr[1010]; struct rangeofx{ float left,right; }range[1010]; bool cmpx(position a, position b){ return a.x<b.x; } bool cmpy(position a, position b){ return a.y>b.y; } float RD(float c,float b){ return sqrt(c*c-b*b); } int main(){ freopen("test.cpp","r",stdin); int n,times=1; float d; while(~scanf("%d %f",&n,&d)){ memset(arr,0,sizeof(arr)); memset(range,0,sizeof(range)); int flag=0; if(n==0&&d==0){ break; } for(int i=0;i<n;i++){ scanf("%f %f",&arr[i].x,&arr[i].y); if(arr[i].y>d) flag=1; } if(flag==1){ printf("Case %d: -1\n",times);times++; continue; } sort(arr,arr+n,cmpy); sort(arr,arr+n,cmpx); for(int i=0;i<n;i++){ range[i].left=arr[i].x-RD(d,arr[i].y); range[i].right=arr[i].x+RD(d,arr[i].y); } int ans = 1; float tmp = range[0].right; for(int i = 1;i < n;i ++) { if(tmp < range[i].left) { ans ++; tmp = range[i].right; } if(tmp > range[i].right) tmp = range[i].right; } printf("Case %d: %d\n",times,ans); times++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator