-
Notifications
You must be signed in to change notification settings - Fork 1
/
OJ_05.cpp
58 lines (54 loc) · 1.37 KB
/
OJ_05.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
#pragma warning(disable:4996)
struct RFpair{
int order;
int rf;
};
int RecmFrnd(bool** FrndMtx, int size, int tar1, int tar2) {
int RecmFrndCnt = 0;
bool tmp1, tmp2;
for (int i = 0; i < size; i++) {
if (i == tar1 || i == tar2) continue;
tmp1 = (tar1 >= i) ? FrndMtx[tar1][i] : FrndMtx[i][tar1];
tmp2 = (tar2 >= i) ? FrndMtx[tar2][i] : FrndMtx[i][tar2];
if (tmp1 && tmp2) RecmFrndCnt++;
}
return RecmFrndCnt;
}
bool cmp(const RFpair tar1, const RFpair tar2) {
return tar1.rf > tar2.rf;
}
int main() {
std::ios::sync_with_stdio(false);
int n, k, u;
std::cin >> n >> k >> u;
bool** FriendMatrix = new bool*[n];
for (int i = 0; i < n; i++) {
FriendMatrix[i] = new bool[i+1];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
bool ipt_buff = 0;
std::cin >> ipt_buff;
if (i >= j) FriendMatrix[i][j] = ipt_buff;
}
}
std::vector<RFpair> result;
for (int i = 0; i < n; i++) {
bool tmp = (u >= i) ? FriendMatrix[u][i] : FriendMatrix[i][u];
if (i == u || tmp ) continue;
int rf = RecmFrnd(FriendMatrix, n, u, i);
if (rf >= k) {
RFpair tmpPair; tmpPair.order = i; tmpPair.rf = rf;
result.push_back(tmpPair);
}
}
stable_sort(result.begin(), result.end(), cmp);
for (int i = 0; i < result.size(); i ++) {
if (i != 0) std::cout << " ";
std::cout << result[i].order;
}
return 0;
}