반응형
https://www.acmicpc.net/problem/17387
ccw을 이용한 문제
평행하는 순간에 예외처리를 해주면된다.
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
|
package algo;
public class B17386 {
static class Pair {
long y;
long x;
public Pair(long x, long y) {
super();
this.y = y;
this.x = x;
}
public boolean cmp(Pair o) {
if (y > o.y)
return true;
if (y == o.y) {
if (x >= o.x)
return true;
}
return false;
}
public boolean equals(Pair obj) {
if(x==obj.x && y==obj.y)
return true;
return false;
}
}
static long ccw(Pair a, Pair b, Pair c) {
long op = a.x * b.y + b.x * c.y + c.x * a.y;
op -= (a.y * b.x + b.y * c.x + c.y * a.x);
// 반시계 방향
if (op > 0)
return 1;
// 시계방향
else if (op == 0)
return 0;
else
return -1;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Pair a = new Pair(sc.nextLong(), sc.nextLong());
Pair b = new Pair(sc.nextLong(), sc.nextLong());
Pair c = new Pair(sc.nextLong(), sc.nextLong());
Pair d = new Pair(sc.nextLong(), sc.nextLong());
if (Solve(a, b, c, d))
System.out.println(1);
else
System.out.println(0);
}
public static boolean Solve(Pair a, Pair b, Pair c, Pair d) {
long abc = ccw(a, b, c);
long abd = ccw(a, b, d);
long cda = ccw(c, d, a);
long cdb = ccw(c, d, b);
if (abc * abd == 0 && cda * cdb == 0) {
if (a.cmp(b)) {
Pair tmp = a;
a = b;
b = tmp;
}
if (c.cmp(d)) {
Pair tmp = c;
c = d;
d = tmp;
}
if(b.equals(c)|| a.equals(d))
return true;
return b.cmp(c)!= a.cmp(d);
}
return abc * abd <= 0 && cda * cdb <= 0;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형
'ProgramSoliving' 카테고리의 다른 글
백준 : 2262 (0) | 2020.05.06 |
---|---|
백준 : 4354 java (0) | 2020.05.05 |
백준 : 3025 java (돌 던지기) (0) | 2020.05.04 |
백준 : 2116 자바 (0) | 2020.05.03 |
백준 : 2113 java (0) | 2020.05.03 |