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 ...
随机推荐
- 数据存储之使用mysql数据库存储数据
推荐安装mysql5.7环境: 官网下载:https://dev.mysql.com/downloads/installer/5.7.html 如果提示没有.NET Framework框架.那么就在提 ...
- Terrorist’s destroy HDU - 4679
Terrorist’s destroy HDU - 4679 There is a city which is built like a tree.A terrorist wants to destr ...
- (原创)task和function语法的使用讨论(Verilog,CPLD/FPGA)
1. Abstract function和task语句的功能有很多的相似之处,在需要有多个相同的电路生成时,可以考虑使用它们来实现.因为个人使用它们比较少,所以对它们没有进行更深的了解,现在时间比较充 ...
- DOS中断及程序调用
http://www.cnblogs.com/ynwlgh/archive/2011/12/12/2285017.html
- Leetcode 872. 叶子相似的树
题目链接 https://leetcode-cn.com/problems/leaf-similar-trees/description/ 题目描述 请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到 ...
- (HTML)A标签伪元素选择器的继承关系
①如果a:link{}也存在,那么不管a{}放到哪里,a{}和a:link{}冲突的属性都会采用a:link{}的,不冲突的属性若存在a{}中,会被a:link{}. a:visited{} .a:h ...
- WPF实现QQ群文件列表动画(一)
QQ群大家都用过,先看下目前QQ的群文件列表容器的效果: 细心点大家就会发现,这玩意收缩和展开是带动画的,并不是很僵硬地直接收缩或者直接展开,毫无疑问,如果用WPF实现这样的效果,这里的最佳控件是Ex ...
- POJ 2311 Cutting Game(SG函数)
Cutting Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4806 Accepted: 1760 Desc ...
- HDU 4825 Xor Sum (trie树处理异或)
Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total S ...
- TCP/IP网络编程之套接字与标准I/O
标准I/O函数 标准标准I/O函数有两个优点: 标准I/O函数具有良好的移植性 标准I/O函数可以利用缓冲提高性能 关于移植性无需过多解释,不仅是I/O函数,所有标准函数都具有良好的移植性.因为,为了 ...