forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe1493.java
More file actions
102 lines (80 loc) · 1.87 KB
/
swe1493.java
File metadata and controls
102 lines (80 loc) · 1.87 KB
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
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class swe1493 {
static Scanner sc = new Scanner(System.in);
static int answer = 0;
static HashMap<vertex, Integer> HM;
public static void main(String[] args) {
int t = sc.nextInt();
for(int T=1; T<=t; T++) {
int p = sc.nextInt();
int q = sc.nextInt();
int N= 300;// p와q는 1~10,000
HM = new HashMap<>();
answer = solution(p,q,N);
System.out.println("#" + T + " " + answer);
}
}
//1,1
//2,1 1,2
//3,1 2,2 1,3
//4,1 3,2 2,3 1,4..
public static int solution(int p, int q, int N)
{
makeVertex(N);
vertex a = new vertex(getKey(HM, p));
vertex b = new vertex(getKey(HM, q));
return getValue(HM,(a.p+b.p), (a.q+b.q));
}
public static int getValue(HashMap<vertex, Integer> m, int p, int q)
{
for(vertex o: m.keySet())
{
if(o.p == p && o.q == q)
{
return m.get(o);
}
}
return 0;
}
public static vertex getKey(HashMap<vertex, Integer> m, int value)
{
for(vertex o: m.keySet())
{
if(m.get(o).equals(value))
{
return o;
}
}
return null;
}
//1,1
//2,1 1,2
//3,1 2,2 1,3
//4,1 3,2 2,3 1,4..
public static void makeVertex(int N)
{
int idx = 1;
for (int i = 1; i <= N; i++) {
for (int j = i; j > 0; j--) {
HM.put(new vertex(i-j+1,j),idx++);
}
}
}
}
class vertex
{
int p;
int q;
public vertex(int p, int q)
{
this.p = p;
this.q = q;
}
public vertex(vertex target)
{
this.p = target.p;
this.q = target.q;
}
}