贪心+预处理
有个点 就是写错了,找了半天哇。 R是double类型不是int类型!
#include <iostream> #include <cstdio> #include <cstring> #include <limits> #include<cmath> #include <algorithm> #define endl ' ' #define _for(i,a,b) for(int i=a;i<b;i++) using namespace std; const int N = 1e4+5; typedef long long ll; int n,d; struct Node{ double l,r; bool operator < ( const Node &o )const{ if( l!=o.l ) return l<o.l; return r<o.r; } }a[N]; int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int Case = 1; while(cin>>n>>d){ int flag = 0; if( n+d==0 ) break; _for(i,0,n){ int x,y; cin>>x>>y; if( flag ) continue; if( abs(y)>d ){ flag = 1; continue; } double py = sqrt( d*d - y*y ); a[i].l = x-py,a[i].r = x+py; } if( flag ){ cout<<"Case "<<Case++<<": "<<-1<<endl; continue; } sort( a,a+n ); double R = a[0].r; int cnt = 1; _for(i,1,n){ if( a[i].r < R ) R = a[i].r; else if( a[i].l > R ){ cnt++; R = a[i].r; } } cout<<"Case "<<Case++<<": "<<cnt<<endl; } return 0; }