| ||||||||||
| 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和y沒有考慮負數也AC了,提供代碼參考#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAXP 1100
int N, d;
typedef struct POINT{
int x, y; //location
double s, e; //start and end position of interval
};
POINT p[MAXP];
int CMP(const void *a, const void *b){
POINT x = *(POINT*)a;
POINT y = *(POINT*)b;
if(x.s > y.s)return 1;
return -1;
}
//count the interval of x-position
void cnt_interval(int index){
double y = (double)p[index].y;
double x = pow(d * d - y * y, 0.5);
p[index].s = (double)p[index].x - x;
p[index].e = (double)p[index].x + x;
}
//count the minimum points that can cover all the points
int count(){
int i, cnt = 1;
//record the right end
double e = p[0].e;
for(i = 0;i < N; i++){
//overlap
if(p[i].s <= e)
e = min(e, p[i].e);
else{
cnt++;
e = p[i].e;
}
}
return cnt;
}
int main(){
int i, j, cases = 0;
bool nosol;
while(1){
scanf("%d %d", &N, &d);
if(!N && !d) break;
//initial
nosol = false;
memset(p, 0, sizeof(p));
//read file
for(i = 0;i < N; i++){
scanf("%d %d", &p[i].x, &p[i].y);
//count the interval
cnt_interval(i);
//if the point is to far from the distance
if(p[i].y > d)
nosol = true;
}
//if no solution
if(nosol){
printf("Case %d: -1\n", ++cases);
continue;
}
//sort the x-axis
qsort(p, N, sizeof(POINT), CMP);
//print the answer
printf("Case %d: %d\n", ++cases, count());
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator