-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
129 lines (95 loc) · 2.78 KB
/
Main.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.company;
import java.util.Locale;
import java.util.Scanner;
class vector
{
double x;
double y;
public vector(double x, double y)
{
this.x = x;
this.y = y;
}
}
public class Main
{
static void MinusCoefficient (double A[][], int first, int second, double coeff)
{
for (int i = 0; i <A[0].length; i++)
{
A[first][i] -= A[second][i]*coeff;
}
}
static void replace (double[][] A, int first, int second)
{
double c = 0;
for (int i = 0; i <A[0].length; i++)
{
c = A[second][i];
A[second][i] = A[first][i];
A[first][i] = c;
}
}
static void divide (double[][] A, int index, double coeff)
{
for (int i = 0; i <A[0].length; i++)
{
A[index][i] /= coeff;
}
}
static vector sum (vector a, vector b) {return new vector(a.x+b.x, a.y+b.y);}
static vector multiply (vector a, double b)
{
return new vector(a.x*b, a.y*b);
}
public static void main(String[] args)
{
Locale.setDefault(Locale.US);
Scanner in = new Scanner(System.in);
vector v1 = new vector(in.nextDouble(), in.nextDouble());
vector d1 = new vector(in.nextDouble(), in.nextDouble());
vector v2 = new vector(in.nextDouble(), in.nextDouble());
vector d2 = new vector(in.nextDouble(), in.nextDouble());
int n = 2;
double[][] A = new double[n][n+1];
A[0][0] = d1.x;
A[0][1] = -d2.x;
A[0][2] = v2.x-v1.x;
A[1][0] = d1.y;
A[1][1] = -d2.y;
A[1][2] = v2.y-v1.y;
int d = 0;
for (int i = 0; i <n; i++)
{
if (A[i][i] == 0)
{
d = 0;
for (int j = i+1; j <n; j++)
{
if (A[j][i] != 0)
{
replace(A, i, j);
d = 1;
break;
}
}
if (d == 0)
{
System.out.println("NOTSINGLE");
System.exit(0);
}
}
for (int j = 0; j <i; j++)
{
MinusCoefficient(A, j, i, A[j][i]/A[i][i]);
divide(A, i, A[i][i]);
}
for (int j = i+1; j <n; j++)
{
MinusCoefficient(A, j, i, A[j][i]/A[i][i]);
divide(A, i, A[i][i]);
}
}
System.out.println(sum(v1, multiply(d1, A[0][n])).x + " " + sum(v1, multiply(d1, A[0][n])).y);
}
}