-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain-backup.cpp
More file actions
225 lines (194 loc) · 6.08 KB
/
Copy pathmain-backup.cpp
File metadata and controls
225 lines (194 loc) · 6.08 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* █████╗ ██████╗ ██████╗ ██╗ ███████╗
* ██╔══██╗██╔════╝ ██╔══██╗██║ ╚══███╔╝
* ███████║██║ ██████╔╝██║ ███╔╝
* ██╔══██║██║ ██╔═══╝ ██║ ███╔╝
* ██║ ██║╚██████╗▄█╗ ██║ ███████╗███████╗
* ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚══════╝╚══════╝
*
* @Author: TieWay59
* @Created: 2021/3/28 20:20
* @Link: https://www.desmos.com/calculator?lang=zh-CN
* @Tags:
*
*******************************************************/
#include <bits/stdc++.h>
#ifdef DEBUG
# include "libs59/debugers.h"
// #define debug(x) cerr <<#x << " = "<<x<<endl;
#else
# define endl '\n'
# define debug(...)
# define max(x,y) ((x)>(y)?(x):(y))
# define min(x,y) ((x)>(y)?(y):(x))
#endif
#define STOPSYNC ios::sync_with_stdio(false);cin.tie(nullptr)
#define MULTIKASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++)
typedef long long ll;
const int MAXN = 2e5 + 59;
const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll llINF = 0x3F3F3F3F3F3F3F3F;
using namespace std;
using pii = pair<int, int>;
using vint = vector<int>;
//const unsigned int COUNT_CONTEST = 3;
const std::string DIR = "./input-case-2.txt";
const std::vector<int> WEIGHT = {3, 5, 8};
const double C_RANK = 0.85;
ll fpow(ll a, ll b, ll mod = MOD) {
if (a % mod == 0) return 0;
ll ret = 1;
a %= mod;
while (b) {
if (b & 1)ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
vector<double> solv_model(const vector<int> &solved) {
double mx{1.0 + *max_element(solved.begin(), solved.end())};
double mn{1.0 + *min_element(solved.begin(), solved.end())};
auto f = [a = mn, b = mx](int x) -> double { return x * 1.0 / (a + x) * b; };
vector<double> res(solved.size());
for (size_t i = 0; i < solved.size(); ++i) res[i] = f(solved[i]);
mx = *max_element(res.begin(), res.end());
mn = *min_element(res.begin(), res.end());
for (size_t i = 0; i < solved.size(); ++i) res[i] = (res[i] - mn + 1) / (mx - mn + 1);
return res;
}
vector<double> rank_model(const vector<int> &rank) {
double mx{double(*max_element(rank.begin(), rank.end()))};
auto f = [b = mx](int x) -> double { return (b - x + 1.0) / b; };
vector<double> res(rank.size());
for (size_t i = 0; i < rank.size(); ++i) res[i] = f(rank[i]);
return res;
}
vector<double> join_model(const vector<double> &_solv_model,
const vector<double> &_rank_model) {
assert(_solv_model.size() == _rank_model.size());
vector<double> res(_solv_model.size());
for (size_t i = 0; i < _solv_model.size(); ++i) {
res[i] = _solv_model[i] * (1 - C_RANK) + _rank_model[i] * C_RANK;
}
return res;
}
vector<double> model(const vector<int> &b_solv, const vector<int> &b_rank) {
return join_model(solv_model(b_solv), rank_model(b_rank));
}
class Team {
public:
string name;
struct Contest {
int solv;
int rank;
double score;
};
vector<Contest> contests;
double sum;
};
string strip(const string &s) {
string res;
stringstream ss(s);
ss >> res;
return res;
}
vector<string> split(const string &raw, const char &del) {
vector<string> vec;
stringstream ss(raw);
static string si;
while (getline(ss, si, del)) {
si = strip(si);
if (si.empty())continue;
vec.emplace_back(si);
}
return vec;
}
void load(vector<Team> &teams) {
string line;
ifstream fin(DIR);
while (getline(fin, line, '\n')) {
auto s = split(line, '\t');
assert(s.size() % 2 == 1);
Team t{s.front(), {}, 0.0};
for (int i = 1; i + 1 < s.size(); i += 2) {
int rank = stoi(s[i]);
int solv = stoi(s[i + 1]);
t.contests.push_back({solv, rank, 0.0});
}
teams.push_back(t);
}
fin.close();
}
void test_teams(const vector<Team> &teams) {
for (const auto &team : teams) {
debug(team.name, team.sum);
for (const auto &con : team.contests) {
debug(con.solv, con.rank, con.score);
}
}
}
void dump(vector<Team> &teams) {
ofstream fout("./output.txt");
for (const auto &t : teams) {
fout << setw(2) << setfill(' ')
<< 1 + int(&t - &teams.front())
<< " "
<< setw(8) << setfill(' ')
<< t.name
<< " "
<< setw(10) << setfill(' ') << fixed << setprecision(5)
<< t.sum
<< " : ";
for (const auto &c : t.contests) {
fout << setw(10) << setfill(' ') << setprecision(5)
<< c.score
<< " \n"[&c == &t.contests.back()];
}
}
fout.close();
}
void solve(int kaseId = -1) {
vector<Team> teams;
load(teams);
// test_teams(teams);
const int contest_count = teams.front().contests.size();
for (int i = 0; i < contest_count; ++i) {
vector<int> solv;
vector<int> rank;
for (auto t : teams) {
solv.emplace_back(t.contests[i].solv);
rank.emplace_back(t.contests[i].rank);
}
auto score = model(solv, rank);
for (int j = 0; j < teams.size(); ++j) {
teams[j].contests[i].score = score[j];
}
}
for (auto &t: teams) {
for (const auto &c: t.contests) {
t.sum += c.score * WEIGHT[&c - &t.contests.front()];
}
}
sort(teams.begin(), teams.end(), [](const auto l, const auto &r) {
return l.sum > r.sum;
});
// test_teams(teams);
dump(teams);
}
void solves() {
MULTIKASE {
solve(kase);
}
}
int main() {
#ifdef DEBUG
// freopen("input.txt", "r+", stdin);
#endif
STOPSYNC;
solve();
return 0;
}
/*
*/