题意:
有n位选手参加编程比赛。比赛有三道题目,每个选手的每道题目都有一个评测之前的预得分,这个分数跟选手的提交程序的时间有关,提交的越早,预得分越大。接下来是系统测试,如果某道题目未通过测试,则为0分,否则得分等于预得分,得分相同的选手,ID小的排在前面。
问是否能给出所有的3n得分满足最后的实际名次,如果可能的话,输出最后一名的最高可能得分。每个预得分均为小于1000的非负整数,最多保留两位小数。
分析:
贪心,尽量选择小的去减掉,如果得分相同的话,考虑一下id
另外还要考虑一下浮点数运算的问题。
本题很简单,代码如下。
代码:
#include<bits/stdc++.h>
#define LL long long
#define ms(s) memset(s, 0, sizeof(s))
using namespace std;
const int maxn = 2e5;
struct Student {
int id;
double score[3];
}s[maxn];
int rank1[maxn];
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int n;
int kase = 0;
while(cin >> n && n) {
cout << "Case " << ++kase << ": ";
if(kase == 28) int w = 1;
for(int i = 1; i <= n; i++) {
s[i].id = i;
cin >> s[i].score[0] >> s[i].score[1]
>> s[i].score[2];
}
for(int i = 1; i <= n; i++) {
cin >> rank1[i];
}
double tot = s[rank1[1]].score[0] + s[rank1[1]].score[1] + s[rank1[1]].score[2];
int id = s[rank1[1]].id;
bool flag = true;
for(int i = 2; i <= n; i++) {
//在后面 则可以相等
// 000 001 010 011 100 101 110 111
double ans[8];
for(int j = 0; j < 8; j++) {
double t = 0;
for(int k = 0; k < 3; k++)
if((j >> k) & 1) t += s[rank1[i]].score[k];
ans[j] = t;
}
double e = ans[7]; //tot
sort(ans, ans + 8); //从小到大尝试删掉
//id大可以相同
bool isok = false;
for(int j = 0; j < 8; j++) {
if((fabs(e - ans[j] - tot) > 1e-6 && (e - ans[j] < tot))
|| (fabs(e - ans[j] - tot) < 1e-6 && s[rank1[i]].id > id)){
tot = e - ans[j];
id = s[rank1[i]].id;
isok = true;
break;
}
}
if(!isok) {
flag = false;
break;
}
}
if(!flag) cout << "No solution" << endl;
else cout << fixed << setprecision(2) << tot << endl;
}
return 0;
}