Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit a57209d

Browse files
authored
Add files via upload
1 parent cd2a096 commit a57209d

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

Java/angry.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-1
1+
5

Java/bin/angry.class

-410 Bytes
Binary file not shown.

Java/src/angry.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ public class angry {
99
public static int N;
1010

1111
public static int launchSim(int power){
12+
//System.out.println("Power: "+power);
1213
int cowsUsed = 0;
1314
int curCow = 0;
15+
int power2 = power*2;
1416
// /int lastCow = field.get(field.size() - 1);
1517
while(curCow < N) {
1618
int pos = field.get(curCow);
1719
curCow++;
20+
//System.out.println("Checking "+curCow + " In range "+curCow + " " + (curCow + 2 * power));
1821
for(int i = pos; i < N; i ++) {
19-
if(field.get(i) < pos + 2 * power) {
22+
23+
if(field.get(i) < pos + power2) {
24+
//System.out.println(field.get(i)+" In range "+i);
2025
curCow++;
2126
}
2227
}
28+
curCow++;
2329
cowsUsed++;
2430
}
2531
return cowsUsed;
@@ -37,25 +43,28 @@ public static void main(String[] args) throws IOException{
3743
field.sort(null);
3844
int answer = -1;
3945
int l = 0;
40-
int r = N;
46+
int r = 1000000000;
4147
while (r - l > 1) {
4248
int m = (l + r) / 2;
43-
if (launchSim(m) > K) {
49+
int t = launchSim(m);
50+
if (t < K) {
51+
r = m;
52+
}else if(K == t) {
53+
//System.out.println("Got it");
4454
r = m;
45-
} else {
55+
//break;
56+
}else {
4657
l = m;
4758
}
4859
}
4960

50-
System.out.println(field);
61+
//System.out.println(field);
5162
//System.out.println(costs);
52-
System.out.println(l +" "+r);
63+
//System.out.println(r +" "+l+" "+answer);
5364
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("angry.out")));
54-
pw.println(answer);
65+
pw.println(r);
5566
pw.close();
56-
for(int i = 0 ; i < N; i ++) {
57-
System.out.println(i+": "+launchSim(N));
58-
}
67+
5968
//System.out.println("");
6069
}
6170

0 commit comments

Comments
 (0)