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

Commit 864f72e

Browse files
raymoraymo
authored andcommitted
Update cowjump.java
1 parent 84bd17b commit 864f72e

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

cowjump.java

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static void main(String[] args) throws IOException{
8282
int output = -1;
8383
for(int i = 0; i < N; i ++) {
8484
StringTokenizer st = new StringTokenizer(f.readLine());
85+
<<<<<<< HEAD
8586
Point a = new Point(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
8687
Point b = new Point(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
8788
boolean status;
@@ -108,6 +109,78 @@ public static void main(String[] args) throws IOException{
108109
pw.println(i+1);
109110
pw.close();
110111
System.exit(0);
112+
=======
113+
a = new Point(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()));
114+
b = new Point(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()));
115+
a = a.setIndex(i);
116+
b = b.setIndex(i);
117+
if(a.compareTo(b) == 1) {
118+
lookup[i][0] = b;
119+
lookup[i][1] = a;
120+
}else {
121+
lookup[i][0] = a;
122+
lookup[i][1] = b;
123+
}
124+
points.add(a);
125+
points.add(b);
126+
segements.add(new LineSegement(a, b));
127+
}
128+
f.close();
129+
points.sort(null);
130+
// Algorthim
131+
int size = points.size();
132+
133+
for(int i = 0; i < size; i ++) {
134+
System.out.println(points.get(i));
135+
}
136+
for(int i =0 ; i < N; i ++) {
137+
System.out.println(Arrays.toString(lookup[i]));
138+
System.out.println(segements.get(i));
139+
}
140+
141+
int currentY = -1;
142+
int index;
143+
// boolean newY = true;
144+
List<Integer> pz = new ArrayList<Integer>();
145+
int[] tbl = new int[N];
146+
int max = -1;
147+
int maxi = -1;
148+
for(int i = 0 ; i < N; i ++) {
149+
Point p = points.get(i);
150+
//index = p.index;
151+
/*if(p.y != currentY) {
152+
currentY = (int) p.y;
153+
continue;
154+
}else {
155+
*/
156+
int state = num(p.index,p,lookup);
157+
System.out.println("Endpoint "+ state + " "+p);
158+
if(state == 0) {
159+
pz.add(p.index);
160+
int sz = pz.size() - 1;
161+
LineSegement newline = segements.get(p.index);
162+
for(int j =0 ;j < sz; j ++ ) {
163+
if(Point.intersection(newline,segements.get(pz.get(j)))) {
164+
System.out.println("Intersectsion at "+segements.get(p.index)+" -|||- "+segements.get(j));
165+
tbl[i] ++;
166+
tbl[j] ++;
167+
if(tbl[i] > max) {
168+
max = tbl[i];
169+
maxi = i;
170+
}
171+
if(tbl[j] > max) {
172+
max = tbl[j];
173+
maxi = j;
174+
}
175+
176+
}
177+
}
178+
}else if(state == 1) {
179+
pz.remove(pz.indexOf(p.index));
180+
181+
}else {
182+
continue;
183+
>>>>>>> parent of c6da410... Long Proofing
111184
}
112185
}*/
113186
}
@@ -117,11 +190,18 @@ public static void main(String[] args) throws IOException{
117190
pw.close();
118191
System.exit(0);
119192

193+
<<<<<<< HEAD
120194
}
121195

122196
}
123197
class Point{
124198
double x,y;
199+
=======
200+
}
201+
class Point implements Comparable<Point>{
202+
double x,y;
203+
int index = -1;
204+
>>>>>>> parent of c6da410... Long Proofing
125205
public Point(double x,double y) {
126206
this.x = x;
127207
this.y = y;
@@ -151,8 +231,98 @@ static boolean intersection(Point a, Point b,Point c, Point d) {
151231
}
152232
return false;
153233
}
234+
<<<<<<< HEAD
154235
public String toString() {
155236
return "("+this.x + ","+ this.y + ")";
237+
=======
238+
// Given three colinear points p, q, r, the function checks if
239+
// point q lies on line segment 'pr'
240+
static boolean onSegment(Point p, Point q, Point r)
241+
{
242+
if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) &&
243+
q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y))
244+
return true;
245+
246+
return false;
247+
}
248+
249+
// To find orientation of ordered triplet (p, q, r).
250+
// The function returns following values
251+
// 0 --> p, q and r are colinear
252+
// 1 --> Clockwise
253+
// 2 --> Counterclockwise
254+
static int orientation(Point p, Point q, Point r)
255+
{
256+
// See https://www.geeksforgeeks.org/orientation-3-ordered-points/
257+
// for details of below formula.
258+
double val = (q.y - p.y) * (r.x - q.x) -
259+
(q.x - p.x) * (r.y - q.y);
260+
261+
if (val == 0) return 0; // colinear
262+
263+
return (val > 0)? 1: 2; // clock or counterclock wise
264+
}
265+
266+
// The main function that returns true if line segment 'p1q1'
267+
// and 'p2q2' intersect.
268+
static boolean intersection(Point p1, Point q1, Point p2, Point q2)
269+
{
270+
// Find the four orientations needed for general and
271+
// special cases
272+
int o1 = orientation(p1, q1, p2);
273+
int o2 = orientation(p1, q1, q2);
274+
int o3 = orientation(p2, q2, p1);
275+
int o4 = orientation(p2, q2, q1);
276+
277+
// General case
278+
if (o1 != o2 && o3 != o4)
279+
return true;
280+
281+
// Special Cases
282+
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
283+
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
284+
285+
// p1, q1 and q2 are colinear and q2 lies on segment p1q1
286+
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
287+
288+
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
289+
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
290+
291+
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
292+
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
293+
294+
return false; // Doesn't fall in any of the above cases
295+
}
296+
static Set<Pair<LineSegement,LineSegement>> notwice = new HashSet<Pair<LineSegement,LineSegement>>();
297+
static boolean intersection(LineSegement a,LineSegement b) {
298+
if(notwice.contains(new Pair<LineSegement,LineSegement>(a,b))) {
299+
return false;
300+
}else {
301+
notwice.add(new Pair<LineSegement,LineSegement>(a,b));
302+
}
303+
return intersection(a.a, a.b, b.a, b.b);
304+
}
305+
public String toString() {
306+
return "("+this.x + ","+ this.y + ","+this.index+")";
307+
}
308+
boolean eq(Point q) {
309+
if(q.x == this.x && q.y == this.y) {
310+
return true;
311+
}
312+
return false;
313+
}
314+
@Override
315+
public int compareTo(Point arg0) {
316+
if(arg0.x == this.x) {
317+
return Double.compare(this.y, this.y);
318+
}else if(this.x > arg0.x) {
319+
return -1;
320+
}else {
321+
return 1;
322+
}
323+
//return Double.compare(this.x, arg0.x);
324+
//return 0;
325+
>>>>>>> parent of c6da410... Long Proofing
156326
}
157327
}
158328

@@ -174,9 +344,17 @@ public double atX(double x) {
174344
return this.a.y * (x/this.a.x);
175345
}
176346
}
347+
<<<<<<< HEAD
348+
public Point atX_(double x) {
349+
return new Point(x,this.atX(x));
350+
}
351+
=======
352+
177353
public Point atX_(double x) {
178354
return new Point(x,this.atX(x));
179355
}
356+
/*
357+
>>>>>>> parent of c6da410... Long Proofing
180358
public String toString() {
181359
return this.a.toString() + " -- "+this.b.toString();
182360
}

0 commit comments

Comments
 (0)