1073 多选题常见计分法
程序员文章站
2024-03-22 08:02:09
...
解题代码
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
typedef pair<string, int> pa;
bool cmp(pa a, pa b) {
return a.second != b.second ? a.second > b.second : a.first < b.first;
}
int main() {
int n, k, temp, cnt;
char c;
cin >> n >> k;
vector<set<char> > v(k);
vector<int> sc(k);
for (int i = 0; i < k; i++) {
cin >> sc[i] >> temp >> cnt;
for (int j = 0; j < cnt; j++) {
getchar();
cin >> c;
v[i].insert(c);
}
}
unordered_map<string, int> mm;
for (int i = 0; i < n; i++) {
double sum = 0;
for (int j = 0; j < k; j++) {
set<char> sn;
getchar(); getchar();
cin >> cnt;
for (int l = 0; l < cnt; l++) {
cin >> c;
sn.insert(c);
}
bool flag = true;
for (auto x : sn) {
if (v[j].find(x) == v[j].end()) {
mm[to_string(j + 1) + "-" + x]++;
flag = false;
}
}
for (auto x : v[j]) {
if (sn.find(x) == sn.end()) {
mm[to_string(j + 1) + "-" + x]++;
}
}
if (flag && sn == v[j]) sum += sc[j];
else if (flag) sum += 0.5*sc[j];
getchar();
}
if (i) printf("\n");
printf("%.1f", sum);
}
if (mm.size() == 0) printf("\nToo simple");
else {
vector<pair<string, int> > vv;
for (auto x : mm) vv.push_back(x);
sort(vv.begin(), vv.end(), cmp);
int M = vv.begin()->second;
for (auto x : vv) {
if (x.second == M)
printf("\n%d %s", M, x.first.c_str());
}
}
return 0;
}
测试结果
问题整理
1.相对柳神,我觉得在考场我还是选择这种方式解题好理解一点,对于位运算符还是不太行的。