uva1612 Guess
和cf的打分有点像啊
因为一共只有三道题,所以每个人的得分最多有8种可能性。把这8种可能性都算出来,存在数组里,排好序备用
排名就是一个天然的链表,给出了扫描的顺序
扫描时,维护两个变量:前一个player的最大得分 recd 和他的ID recdID
扫描到每个player时,从大到小遍历他的8种得分,如果有等于recd的得分,且这个player的ID大于recdID,则只需更新recdID。否则遇到第一个小于recd的得分,就更新recd和recdID。
如果在遍历完8种得分后,还没有满足上面两种情况的,则说明无解
不超过1000,两位小数,可以先*100.0,最后输出/100.0就可以减少误差
tmp_i[j] = (int)(round(tmp_f[j] * 100.0)); //注意转换
位运算: if(j & (1 << k)) 取j从右向左第k+1位
for(int j = 0; j < 8; j++) { //对应3个值取不取的8种情况(111,110,101...)
P[i].score[j] = 0;
for(int k = 0; k < 3; k++)
if(j & (1 << k))
P[i].score[j] += tmp_i[k];
}
sort(P[i].score, P[i].score + 8);
#include<cstdio>
#include<algorithm>
#include<cmath>
const int maxn = ; using namespace std; struct player{
int score[];
}P[maxn]; int nn, ID[maxn];
void read(int n){
double tmp_f[];
int tmp_i[];
for(int i = ; i <= n; i++) {
scanf("%lf%lf%lf", &tmp_f[], &tmp_f[], &tmp_f[]);
for(int j = ; j < ; j++)
tmp_i[j] = (int)(round(tmp_f[j] * 100.0)); for(int j = ; j < ; j++) {
P[i].score[j] = ;
for(int k = ; k < ; k++)
if(j & ( << k))
P[i].score[j] += tmp_i[k];
}
sort(P[i].score, P[i].score + );
}
} int main() {
int kase = ;
while(scanf("%d", &nn) == && nn) {
read(nn);
for(int i = ; i <= nn; i++)
scanf("%d", &ID[i]); int MAX = P[ID[]].score[]; //贪心策略
int pre_ID = ID[], i;
for(i = ; i <= nn; i++) {
int cur_ID = ID[i];
bool flag = false;
for(int j = ; j >= ; j--) {
if(P[cur_ID].score[j] == MAX && cur_ID > pre_ID) {
flag = true;
pre_ID = cur_ID;
break;
}
if(P[cur_ID].score[j] < MAX) {
flag = true;
pre_ID = cur_ID;
MAX = P[cur_ID].score[j];
break;
}
}
if(!flag)
break;
}
printf("Case %d: ", kase++);
if(i != nn + )
printf("No solution\n");
else
printf("%.2lf\n", MAX / 100.0);
}
return ;
}
uva1612 Guess的更多相关文章
- UVA-1612 Guess (贪心)
题目大意:考试共有三道题,n个人,每个人对每道题的可能得分已知,现在已知考后排名情况,问排名合不合理. 题目分析:贪心.贪心策略:每处理一个排名,都让他的得分尽量高. # include<ios ...
随机推荐
- 洛谷P1113杂物——DP
题目:https://www.luogu.org/problemnew/show/P1113 每个任务的时间就是准备工作中完成最晚的那个的时间再加上自己的时间. 代码如下: #include<i ...
- Java调用外部类定义的方法(Static与无Static两种)
首先定义方法 public class Dy { public int Add(int x,int y){ //定义Add(),该方法没有被static修饰 return x+y; } public ...
- 算法练习--LeetCode--54. Spiral Matrix 100%
Spiral MatrixMedium Given a matrix of m x n elements (m rows, n columns), return all elements of t ...
- python 类属性和实例属性、方法 访问权限问题
class Animal: cls_attr = 'cls_attr' _cls_attr = '_cls_attr' __cls_attr = '__cls_attr' def __init__(s ...
- bzoj 4589: Hard Nim【线性筛+FWT+快速幂】
T了两次之后我突然意识到转成fwt形式之后,直接快速幂每次乘一下最后再逆回来即可,并不需要没此次都正反转化一次-- 就是根据nim的性质,先手必输是所有堆个数异或和为0,也就变成了一个裸的板子 #in ...
- C#读取大文件
有些时候需要读取文件,小文件的时候效率的影响可以忽略,但是当文件上M,上G的时候,这个时候,效率问题就非常重要了,下面将对一个3G的文件,用C#的方式读取,对比效率的影响. 1. FileStream ...
- C# 多线程(转)
C#多线程 一.基本概念 1.进程 首先打开任务管理器,查看当前运行的进程: 从任务管理器里面可以看到当前所有正在运行的进程.那么究竟什么是进程呢? 进程(Process)是Windows系统中的 ...
- excel导入phpmyadmin
1.将excel文件另存为txt文件,再将txt文件保存为.csv文件同时修改编码为UTF8 2.登录phpmyadmin,在phpmyadmin中创建好表格,按excel中的顺序创建每列 3.因为p ...
- HDU - 6063 RXD and math
Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6063 打表发现规律是n^k #include <iostream> #inc ...
- Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) J
Description Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their comm ...