forked from ravipatel447/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurling.java
134 lines (126 loc) · 3.9 KB
/
curling.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import java.util.*;
import java.lang.*;
import java.io.*;
class curling {
public static void main(String[] args) throws java.lang.Exception {
try {
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
int tc = t;
while (t-- != 0) {
int rb = sc.nextInt();
int rh = sc.nextInt();
int r = sc.nextInt();
double arr[] = new double [r];
int cr = 0;
for(int i=0;i<r;i++){
int x1 = sc.nextInt();
int y1 = sc.nextInt();
arr[i]= circle(0, 0, x1, y1, rh, rb);
}
Arrays.sort(arr);
int y = sc.nextInt();
double ary[] = new double [y];
int cy = 0;
for(int i=0;i<y;i++){
int x1 = sc.nextInt();
int y1 = sc.nextInt();
ary[i]= circle(0, 0, x1, y1, rh, rb);
}
Arrays.sort(ary);
for(int i=0;i<r;i++){
if(y>0){
if( arr[i]<ary[0] && arr[i]!=Double.MAX_VALUE){
cr++;
}
else{
break;
}
}
else{
if(arr[i]!=Double.MAX_VALUE){
cr++;
}
else{
break;
}
}
}
for(int i=0;i<y;i++){
if(r>0){
if(ary[i]<arr[0] && ary[i]!=Double.MAX_VALUE){
cy++;
}
else{
break;
}
}
else{
if(ary[i]!=Double.MAX_VALUE){
cy++;
}
else{
break;
}
}
}
pw.print("Case #"+(tc-t)+": "+cr+" "+cy);
// pw.print("Case #"+(tc-t)+": "+((cr<cy)?0:(cr-cy))+" "+((cr>cy)?0:(cy-cr)));
pw.println();
}
pw.flush();
} catch (Exception e) {
System.out.println(e);
return;
}
}
static double circle(int x1, int y1, int x2, int y2,
int r1, int r2)
{
double d = Math.sqrt((x1 - x2) * (x1 - x2)
+ (y1 - y2) * (y1 - y2));
if (d <= r1 + r2) {
return d;
}
else {
return Double.MAX_VALUE;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}