-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
88 lines (76 loc) · 2 KB
/
main.cpp
File metadata and controls
88 lines (76 loc) · 2 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
#include <bits/stdc++.h>
#include <Windows.h>
#include <locale>
using namespace std;
int _N, _M;
vector<int> dat;
vector<vector<char>> cmpdat;
void qsort();
void qsort(int fr, int to);
bool cmp(int a, int b);
int main(void)
{
srand(time(0));
setlocale(LC_ALL, "");
wprintf(L"후보 수 : ");
scanf("%d", &_N);
wprintf(L"TOP 몇까지? : ");
scanf("%d", &_M);
cmpdat.assign(_N, vector<char>(_N, 0));
for (int i = 1; i <= _N; i++) dat.push_back(i);
qsort();
printf("------------------\n");
for (int i = 0; i < _M; i++) wprintf(L"%d위 : %d번\n", i + 1, dat[i]);
system("pause>nul");
return 0;
}
void qsort() { qsort(0, _N); }
void qsort(int fr, int to)
{
if (to - fr < 2) return;
random_shuffle(dat.begin() + fr, dat.begin() + to);
int pivot = fr;
int f = fr + 1, t = to - 1;
while (f <= t)
{
while (f <= t && cmp(dat[f], dat[pivot])) f++;
while (f <= t && cmp(dat[pivot], dat[t])) t--;
if (f <= t) swap(dat[f], dat[t]);
else swap(dat[pivot], dat[t]);
}
pivot = t;
if (pivot > 1) qsort(fr, pivot);
if (pivot < _M - 1) qsort(pivot + 1, to);
}
bool cmp(int a, int b)
{
if (a == b) return -1;
if (cmpdat[a - 1][b - 1]) return cmpdat[a - 1][b - 1] == 1;
int c;
while (true)
{
printf("%d vs %d --> ", a, b);
scanf("%d", &c);
if (c == a || c == b) break;
wprintf(L"뒤질래? 다시해\n");
}
cmpdat[a - 1][b - 1] = c == a ? 1 : -1;
cmpdat[b - 1][a - 1] = -cmpdat[a - 1][b - 1];
for (int k = 0; k < _N; k++)
{
for (int i = 0; i < _N; i++)
{
if (k == i) continue;
for (int j = 0; j < _N; j++)
{
if (k == j || i == j) continue;
if (cmpdat[i][k] * cmpdat[k][j] == 1)
{
cmpdat[i][j] = cmpdat[i][k];
cmpdat[j][i] = -cmpdat[i][j];
}
}
}
}
return cmpdat[a - 1][b - 1] == 1;
}