UVALive 3664:Guess(贪心 Grade E)
题意:
有n (n<16345)个人,每个人有三个数(小于1000且最多两位小数点),表示答对对应题的得分。规定总分越高的人rank越高。总分相同,id小的rank高。现在知道rank,问这个rank是否可能,如果可能,那么rank最小的那个人的最大得分是多少。
思路:
3个数,最多8种情况。然后从rank小往上推,每次选择一个最小的能符合条件的分数,当作这个人的分数。如果能推下去,则ok,否则,不能。
坑点:
精度很坑。转成整数才过了。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define N 20000 struct Man{
int a[];
int possible[];
void read() {
for (int i = ; i < ; i++) {
double tmp;
scanf("%lf", &tmp);
a[i] = (int)((tmp+1e-)*);
}
for (int i = ; i < ; i++) {
int sum = ;
for (int j = ; j < ; j++) {
if ((i>>j)&) {
sum += a[j];
}
}
possible[i] = sum;
}
sort(possible, possible+);
}
}man[N];
int rk[N];
int n; bool dfs(int pre, int id) {
if (id <= ) return true;
int minres = 0x3f3f3f3f;
bool isok = false;
for (int i = ; i >= ; i--) {
if (man[rk[id]].possible[i] > pre || (man[rk[id]].possible[i] == pre && rk[id] < rk[id+])) {
isok = true;
minres = min(minres, man[rk[id]].possible[i]);
} else break;
}
if (!isok) return false; return dfs(minres, id-);
} int main() {
int cas = ;
while (scanf("%d", &n)!=EOF) {
if (n == ) break;
printf("Case %d: ", cas++);
for (int i = ; i <= n; i++) {
man[i].read();
}
for (int i = ; i <= n; i++) {
scanf("%d",&rk[i]);
} int ans = -;
for (int i = ; i < ; i++) {
if (dfs(man[rk[n]].possible[i], n-)) {
ans = max(ans, man[rk[n]].possible[i]);
} else break;
} if (ans == -) {
puts("No solution");
} else {
printf("%.2f\n", ans/100.0);
}
}
return ;
}
UVALive 3664:Guess(贪心 Grade E)的更多相关文章
- UVALive 3835:Highway(贪心 Grade D)
VJ题目链接 题意:平面上有n个点,在x轴上放一些点,使得平面上所有点都能找到某个x轴上的点,使得他们的距离小于d.求最少放几个点. 思路:以点为中心作半径为d的圆,交x轴为一个线段.问题转换成用最少 ...
- UVALive 3507:Keep the Customer Satisfied(贪心 Grade C)
VJ题目链接 题意: 知道n(n <= 8e6)个工作的完成所需时间q和截止时间d,你一次只能做一个工作.问最多能做多少工作? 思路: 首先很像贪心.观察发现如下两个贪心性质: 1)一定存在一个 ...
- UVAlive 2911 Maximum(贪心)
Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...
- uvalive 2911 Maximum(贪心)
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...
- UVALive - 4225(贪心)
题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...
- UVALive 4850 Installations 贪心
题目链接 题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...
- UVALive 4863 Balloons 贪心/费用流
There will be several test cases in the input. Each test case will begin with a line with three inte ...
- UVALive - 6268 Cycling 贪心
UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:
- UVALive 4731 dp+贪心
这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...
随机推荐
- Python入门基础--变量与基本数据类型
变量 什么是变量 变量就是变化的量,变就是变化,量用于衡量描述对象的状态 为什么要有变量 程序执行的本质就是一系列状态的变化,变是程序执行的直接体现,所以我们需要有一种机制能够反映或者说是保存下来程序 ...
- (转)RubyGems常用命令
什么是RubyGems? RubyGems是一个方便而强大的Ruby程序包管理器,Ruby的第三方插件是用gem方式来管理,非常容易发布和共享,一个简单的命令就可以安装上第三方的扩展库.特点:能远程安 ...
- Jack Straws POJ - 1127 (简单几何计算 + 并查集)
In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table ...
- V4L2学习(二)结构介绍
v4l2_device v4l2_device在v4l2框架中充当所有v4l2_subdev的父设备,管理着注册在其下的子设备.以下是v4l2_device结构体原型(去掉了无关的成员): struc ...
- Intellij Idea 创建JavaWeb项目
折腾Tomcat折腾了两个晚上,第一个晚上怎么都进不了Tomcat的首页,第二个晚上进去了,但是新建的Web项目,在浏览器中运行,总是 Error on Apache Tomcat: The requ ...
- NodeJs初学者经典入门解析
Node.js 是一个基于谷歌浏览器JavaScript执行环境建立的一个平台,让JavaScript可以脱离客户端浏览器运行,让 JavaScript具有服务器语言的能力.我们可以使用NodeJs方 ...
- leetcode 【 Two Sum 】python 实现
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- Python-S9-Day88——stark组件之设计urls
03 stark组件之设计urls 04 stark组件之设计urls2 05 stark组件之设计list_display 06 stark组件之z查看页面的数据展示 03 stark组件之设计ur ...
- PHP PDO fetch() 详解
环境:(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0) PDOStatement::fetch — 从结果集中获取下一行 说明 PDOStatement ...
- CodeForces Round #498 Div.3 A. Adjacent Replacements
http://codeforces.com/contest/1006/problem/A Mishka got an integer array aa of length nn as a birthd ...