📄 3209001_wa.java
字号:
import java.util.*;
import java.math.*;
public class Main
{
final double eps = 1e-8;
class TPoint implements Comparable <TPoint>
{
int x, y;
TPoint (int x,int y)
{
this.x = x;
this.y = y;
}
public int compareTo(TPoint that)
{
if(this.x == that.x)
return that.y - this.y;
else
return this.x - that.x;
}
}
public static void main(String [] args)
{
new Main().run();
}
private void run()
{
double L, D;
int n;
TPoint [] p;
int cas = 1;
Scanner in = new Scanner (System.in);
while(true)
{
n = in.nextInt();
D = in.nextDouble();
if(n==0&&D==0)
break;
System.out.print("Case "+cas+": ");
cas++;
p = new TPoint [n+1];
for(int i = 0; i < n; i++)
{
p[i] = new TPoint(in.nextInt(),in.nextInt());
}
Arrays.sort(p,0,n);
int cnt = 0;
boolean fail = false;
if(D <= 0)
{
fail = true;
}
if(fail)
{
System.out.println("-1");
continue;
}
for(int i = 0; i < n; i++)
{
double x = p[i].x;
double y = p[i].y;
if(Math.abs(y) > D)
{
fail = true;
break;
}
double X = Math.sqrt(D*D-y*y)+x;
int j = i;
while(j < n&&Math.hypot((double)p[j].y,X-(double)p[j].x) <= D+eps)
{
j++;
}
i = j - 1;
cnt++;
}
System.out.println(fail?"-1":cnt);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -