题意:有n(n<=16384)位选手参加编程比赛。比赛有3道题目,每个选手的每道题目都有一个评测之前的预得分(这个分数和选手提交程序的时间相关,提交得越早,预得分越大)。接下来是系统测试。如果某道题目未通过测试,则该题的实际得分为0分,否则得分等于预得分。得分相同的选手,ID小的排在前面。

已知所有人的预得分,以及最终的排名,问这个排名是否可能存在,若存在,输出最后一名的最高可能得分;否则,输出No solution。每个预得分均为小于1000的非负实数,最多保留两位小数。

分析:

1、因为要保证最后一名的最高可能总分最高,所以排名在前面的人每次递减的分要尽可能少,排名第一的人分数自然不用减少。

2、如果分数与前一个名次的人相同,但是ID比前一个名次的人大,那就没必要减少总分。

3、如果分数本来就比前一个名次的人低,也没必要减少总分。

4、如果不满足条件2和3,那么就需要减少分数,假设一个人三个题目预得分为a,b,c,那么可能减少的分数是a,b,c,a+b,a+c,b+c,a+b+c,排序后,尽可能少的减少分数。

注意如果ID比前一个名次的人大,那么减少到与前一个名次的人总分相同时即可;否则,要减少到比前一个名次的人的总分小。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 16384 + 10;
const int MAXT = 10000 + 10;
inline int dcmp(double a, double b) {
if(fabs(a - b) < eps) return 0;
return a < b ? -1 : 1;
}
using namespace std;
struct Node{
double a, b, c, tot;
double sum[10];
void read(){
scanf("%lf%lf%lf", &a, &b, &c);
tot = a + b + c;
sum[0] = a;
sum[1] = b;
sum[2] = c;
sum[3] = a + b;
sum[4] = b + c;
sum[5] = a + c;
sum[6] = a + b + c;
sort(sum, sum + 7);
}
}num[MAXN];
int a[MAXN];
int main(){
int n;
int kase = 0;
while(scanf("%d", &n) == 1){
if(!n) return 0;
for(int i = 0; i < n; ++i){
num[i].read();
}
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
printf("Case %d: ", ++kase);
if(n <= 0){
printf("No solution\n");
continue;
}
bool flag = true;
for(int i = 0; i < n; ++i){
if(!i) continue;
else if(dcmp(num[a[i] - 1].tot, num[a[i - 1] - 1].tot) == 0){
if(a[i] > a[i - 1]) continue;
}
else if(dcmp(num[a[i] - 1].tot, num[a[i - 1] - 1].tot) == -1) continue;
bool ok = false;
for(int j = 0; j < 7; ++j){
if(dcmp(num[a[i] - 1].tot - num[a[i] - 1].sum[j], num[a[i - 1] - 1].tot) == -1 || (dcmp(num[a[i] - 1].tot - num[a[i] - 1].sum[j], num[a[i - 1] - 1].tot) == 0 && a[i] > a[i - 1])){
num[a[i] - 1].tot -= num[a[i] - 1].sum[j];
ok = true;
break;
}
}
if(!ok){
flag = false;
break;
}
}
if(!flag){
printf("No solution\n");
}
else{
printf("%.2lf\n", num[a[n - 1] - 1].tot);
}
}
return 0;
}

  

UVA - 1612 Guess (猜名次)(贪心)的更多相关文章

  1. UVa 1612 Guess (贪心+题意)

    题意:有 n 位选手参加编程比赛.比赛有3道题目,每个选手的每道题目都有一个评测之前的预得分(这个分数和选手提交程序的时间相关,提交的越早,预得分越大). 接下来 是系统评测.如果某道题未通过测试,则 ...

  2. 紫书 习题8-8 UVa 1612 (贪心+精度)

    这道题我很快就写出来了, 但是一直WA, 然后发现是精度, 这坑了我一个小时-- (1)贪心.每次就尽量分数高, 可以保证最后分数最高 (2)神tm精度问题.记住判断大于小于和等于的时候要用EPS(1 ...

  3. 【uva 1612】Guess(算法效率,2种想法)

    题意:已知 N 位选手的3题的预期得分,得分要不全拿,要不为0.且知道最后的实际名次,而且得分相同的选手,ID小的排在前面.问这样的名次可能吗.若可能,输出最后一名的最高可能得分.(N≤16384) ...

  4. 【NOIP合并果子】uva 10954 add all【贪心】——yhx

    Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvesconde ...

  5. uva 11134 fabled rooks (贪心)——yhx

    We would like to place n rooks, 1 n 5000, on a n nboard subject to the following restrictions• The i ...

  6. UVa 11134 (区间上的贪心) Fabled Rooks

    这道题真是WA得我心力交瘁,好讨厌的感觉啊! 简直木有写题解的心情了 题意: n×n的棋盘里,放置n个车,使得任意两车不同行且不同列,且第i个车必须放在给定的第i个矩形范围内.输出一种方案,即每个车的 ...

  7. UVA 12382 Grid of Lamps 贪心

    题目链接: C - Grid of Lamps Time Limit:1000MSMemory Limit: 0KB 问题描述 We have a grid of lamps. Some of the ...

  8. uva 993 Product of digits (贪心 + 分解因子)

      Product of digits  For a given non-negative integer number N , find the minimal natural Q such tha ...

  9. UVA 11729 - Commando War(贪心 相邻交换法)

    Commando War There is a war and it doesn't look very promising for your country. Now it's time to ac ...

随机推荐

  1. Java-android使用GridView布局的电子相册&服务器获取图片

    转  http://www.tuicool.com/articles/B7JNv2 电子相册的思路: 1.先是考虑布局,我用的是GridView布局 2.GridView中又该怎么显示图片,其实我的这 ...

  2. java程序员的就业指导(重点)

    想要成为合格的Java程序员或工程师到底需要具备哪些专业技能,面试者在面试之前到底需要准备哪些东西呢?本文陈列的这些内容既可以作为个人简历中的内容,也可以作为面试的时候跟面试官聊的东西,你可以把这些内 ...

  3. PHP登陆页面完整代码

      /* 包括的文件 */ /* login.php */ <?phprequire('./mysql.php');$username=$_REQUEST['username'];$passwd ...

  4. poj1703 Find them, Catch them(种类并查集

    题目地址:http://poj.org/problem?id=1703 题目大意:警察抓了n个坏蛋,这些坏蛋分别属于龙帮或蛇帮.输入m个语句,A x y询问x和y的关系(在一个帮派,不在,不能确定), ...

  5. 白手起家Django项目发布下篇_Django项目nginx部署

    上一篇完成了python的安装,接下来安装python的依赖包和项目的依赖包 1.  python-devel 命令:yum -y install python-devel 安装Django1.8.2 ...

  6. Ubuntu 16.04 系统编译部署lamp服务。

    壹  下载Apache 和 PHP源码包: Apache:http://httpd.apache.org/download.cgi PHP:http://php.net/downloads.php 贰 ...

  7. HiBench成长笔记——(7) 阅读《The HiBench Benchmark Suite: Characterization of the MapReduce-Based Data Analysis》

    <The HiBench Benchmark Suite: Characterization of the MapReduce-Based Data Analysis>内容精选 We th ...

  8. linux中df和du查看磁盘大小不一致解决方法

    挂了一块50G到/data目录下#  df -h Filesystem Size Used Avail Use% Mounted on /dev/xvdb1 50G 46G 1.2G 98% /dat ...

  9. Unbutu下装oracle

    Ubuntu 16.04安装Oracle 11gR2入门教程图文详解 转自         https://www.linuxidc.com/Linux/2017-12/149797.htm  原文作 ...

  10. jenkins#安装jenkins

    1. 访问官网下载地址https://jenkins.io/zh/download/ 2. 选择自己的平台,然后按照文档进行操作: 主要按照文档来,下面是我按照文档按照的一个记录 #访问 https: ...