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

Commit c6da410

Browse files
authored
Long Proofing
Changed lots of things to long to deal with integer overflow
1 parent 8cd4441 commit c6da410

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

cowjump.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public static void main(String[] args) throws IOException{
5353
for(int i =0 ; i < N; i ++) {
5454
Point a,b;
5555
StringTokenizer st = new StringTokenizer(f.readLine());
56-
a = new Point(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()));
57-
b = new Point(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()));
56+
a = new Point(Long.parseLong(st.nextToken()),Long.parseLong(st.nextToken()));
57+
b = new Point(Long.parseLong(st.nextToken()),Long.parseLong(st.nextToken()));
5858
a = a.setIndex(i);
5959
b = b.setIndex(i);
6060
if(a.compareTo(b) == 1) {
6161
lookup[i][0] = b;
6262
lookup[i][1] = a;
6363
}else {
64-
lookup[i][0] = a;
65-
lookup[i][1] = b;
64+
lookup[i][0] = a;
65+
lookup[i][1] = b;
6666
}
6767
points.add(a);
6868
points.add(b);
@@ -80,14 +80,13 @@ public static void main(String[] args) throws IOException{
8080
System.out.println(Arrays.toString(lookup[i]));
8181
System.out.println(segements.get(i));
8282
}
83-
8483
int currentY = -1;
8584
int index;
8685
// boolean newY = true;
8786
List<Integer> pz = new ArrayList<Integer>();
88-
int[] tbl = new int[N];
89-
int max = -1;
90-
int maxi = -1;
87+
long[] tbl = new long[N];
88+
long max = -1;
89+
long maxi = -1;
9190
for(int i = 0 ; i < N; i ++) {
9291
Point p = points.get(i);
9392
//index = p.index;
@@ -137,9 +136,9 @@ public static void main(String[] args) throws IOException{
137136

138137
}
139138
class Point implements Comparable<Point>{
140-
double x,y;
139+
long x,y;
141140
int index = -1;
142-
public Point(double x,double y) {
141+
public Point(long x,long y) {
143142
this.x = x;
144143
this.y = y;
145144
}
@@ -206,10 +205,10 @@ static boolean intersection(Point p1, Point q1, Point p2, Point q2)
206205
{
207206
// Find the four orientations needed for general and
208207
// special cases
209-
int o1 = orientation(p1, q1, p2);
210-
int o2 = orientation(p1, q1, q2);
211-
int o3 = orientation(p2, q2, p1);
212-
int o4 = orientation(p2, q2, q1);
208+
long o1 = orientation(p1, q1, p2);
209+
long o2 = orientation(p1, q1, q2);
210+
long o3 = orientation(p2, q2, p1);
211+
long o4 = orientation(p2, q2, q1);
213212

214213
// General case
215214
if (o1 != o2 && o3 != o4)
@@ -251,7 +250,7 @@ boolean eq(Point q) {
251250
@Override
252251
public int compareTo(Point arg0) {
253252
if(arg0.x == this.x) {
254-
return Double.compare(this.y, this.y);
253+
return Long.compare(this.y, this.y);
255254
}else if(this.x > arg0.x) {
256255
return -1;
257256
}else {
@@ -283,10 +282,11 @@ public double atX(double x) {
283282
return this.a.y * (x/this.a.x);
284283
}
285284
}
286-
285+
/*
287286
public Point atX_(double x) {
288287
return new Point(x,this.atX(x));
289288
}
289+
*/
290290
/*
291291
public String toString() {
292292
return this.a.toString() + " -- "+this.b.toString();

0 commit comments

Comments
 (0)