-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.cs
105 lines (92 loc) · 3.34 KB
/
main.cs
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
using System;
class Solution
{
private static readonly int MAX_N = 100;
static double SmallerPartWeight(int n, int[] x, int[] y, int[] v)
{
double minDiff = double.MaxValue;
double smallerPartWeight = 0.0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i != j)
{
double onePartWeight = 0.0;
double otherPartWeight = 0.0;
if (y[i] == y[j])
{
for (int k = 0; k < n; k++)
{
if (k != i && k != j)
{
if (y[k] > y[i])
{
onePartWeight += v[k];
}
else
{
otherPartWeight += v[k];
}
}
}
}
else
{
double a = (x[i] - x[j]) / (y[i] - y[j]);
double b = y[i] - a * x[i];
for (int k = 0; k < n; k++)
{
if (k != i && k != j)
{
if (y[k] > a * x[k] + b)
{
onePartWeight += v[k];
}
else
{
otherPartWeight += v[k];
}
}
}
}
double diffA, diffB;
diffA = Math.Abs((onePartWeight + v[i]) - (otherPartWeight + v[j]));
diffB = Math.Abs((onePartWeight + v[j]) - (otherPartWeight + v[i]));
if (diffA < diffB)
{
if (diffA < minDiff)
{
minDiff = diffA;
smallerPartWeight = (onePartWeight + v[i]) < (otherPartWeight + v[j]) ? (onePartWeight + v[i]) : (otherPartWeight + v[j]);
}
}
else
{
if (diffB < minDiff)
{
minDiff = diffB;
smallerPartWeight = (onePartWeight + v[j]) < (otherPartWeight + v[i]) ? (onePartWeight + v[j]) : (otherPartWeight + v[i]);
}
}
}
}
}
return smallerPartWeight;
}
static void Main(string[] args)
{
int N = Convert.ToInt32(Console.ReadLine());
int[] x = new int[N];
int[] y = new int[N];
int[] v = new int[N];
for (int i = 0; i < N; i++)
{
string[] xyv = Console.ReadLine().Split(' ');
x[i] = Convert.ToInt32(xyv[0]);
y[i] = Convert.ToInt32(xyv[1]);
v[i] = Convert.ToInt32(xyv[2]);
}
Console.WriteLine(SmallerPartWeight(N, x, y, v));
}
}