HDU2976 Dropping tests 2017-05-11 18:10 39人阅读 评论(0) 收藏
Dropping tests
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be
Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are allowed to drop any k of your test scores. Suppose you take 3 tests with scores of 5/5, 0/1, and 2/6. Without dropping any tests, your cumulative average is Input The input test file will contain multiple test cases, each containing exactly three lines. The first line contains two integers, 1 ≤ n ≤ 1000 and 0 ≤ k < n. The second line contains n integers indicating ai for Output For each test case, write a single line with the highest cumulative average possible after dropping k of the given test scores. The average should be rounded to the nearest integer. Sample Input 3 1 Sample Output 83 Hint To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997). Source |
————————————————————————————————
给出n和分数,可以去其中m个,求剩下的分子之和除以分母之和最大
思路:二分答案,验证去了m个后能否达到
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int n,m;
struct node{
LL a,b;
}p[100005];
double k; bool cmp(node a,node b)
{
double x=a.a-(a.b*k);
double y=b.a-(b.b*k);
return x>y;
} bool ok(double mid)
{
k=mid;
sort(p,p+n,cmp);
LL x=0,y=0;
for(int i=0;i<n-m;i++)
{
x+=p[i].a;
y+=p[i].b;
}
double ans=x*1.0/y;
if(ans>=mid)
return 1;
return 0; } int main()
{
while(~scanf("%d%d",&n,&m)&&(m||n))
{
for(int i=0;i<n;i++)
scanf("%lld",&p[i].a);
for(int i=0;i<n;i++)
scanf("%lld",&p[i].b); double l=0,r=1;
while(r-l>1e-5)
{
double mid=(l+r)/2;
if(ok(mid))
{
l=mid;
}
else
r=mid;
}
l*=100;
printf("%.0f\n",l);
}
return 0;
}
HDU2976 Dropping tests 2017-05-11 18:10 39人阅读 评论(0) 收藏的更多相关文章
- const char*, char const* and char *const 分类: C/C++ OpenCV 2014-11-08 18:10 114人阅读 评论(0) 收藏
const char*, char const*, char*const的区别问题几乎是C++面试中每次都会有的题目. 事实上这个概念谁都有只是三种声明方式非常相似很容易记混. Bjarne在他的 ...
- Codeforces777E. Hanoi Factory 2017-05-04 18:10 42人阅读 评论(0) 收藏
E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- spark1.3.1使用基础教程 分类: B8_SPARK 2015-04-28 11:10 1651人阅读 评论(0) 收藏
spark可以通过交互式命令行及编程两种方式来进行调用: 前者支持scala与python 后者支持scala.python与java 本文参考https://spark.apache.org/d ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏
Building Shops Time Limit: 2000/1000 MS ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- HDU6205 Coprime Sequence 2017-05-07 18:56 36人阅读 评论(0) 收藏
Coprime Sequence Time Limit: 2000/1000 MS (Ja ...
- codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- adb的一些常用的命令
如果在dos界面想要直接用adb的话,需要将anroidsdk安装目录下的tools和platform-tools以及加入到环境变量path中. 查看当前的设备(包括真机和模拟器):adb devic ...
- homework 补第三题
上次只写了两道题 发现少了一道 所以今天补上 4 . 另外补上今天的程序代码 代码 1. 2. 3 4 运行截图 1. 2 3
- c pointer
1. 定义数组后,数组名是一个常数, 而指针是一个变量 如下: int a[10]; int *p; p=a; \\ 与 p=&a[0]等价 则*p++表示 a[1] 而 a++ 则是错误的 ...
- datagrid数据表格的维护
想想刚开始学jsp, 用application做一个简单的数据库, 简单的注册页面, 跟这个相比就是过家家 <%@ page language="java" contentT ...
- Windows系统之hosts文件
对于Hosts文件相信很多Win7的系统用户会比较陌生,其实Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,所以功 ...
- js简单校验form表单
/** * 数据简单校验 */ function checkData (formId) { var check = true; var emailReg = new RegExp("^[a- ...
- JavaScript的数据类型和运算符总结
1.定义变量用关键字 var var a = 1 var b = "abc" 2.javascript脚本每一行要用分号隔开 3.javascript的代码一般放在html代码的最 ...
- 1-QT-文件操作
Qt文本文件的读写操作 Qt文件操作详解(创建.写入.删除.INI.XML文件等 二进制文件的读写文件可以使用QFile类.QStream文本文件的读写建议使用QTextStream类,它操作文件更加 ...
- B/S与C/S的比较
1.C/S需要安装客户端软件,比如我们的qq就是C/S模式下的软件.如果使用这些软件我们必须先要下载客户端软件.如果软件更新了,就需要下载新的客户端进行更新. 2.B/S无需安装客户端软件,比如我们的 ...
- 相机拍摄时最重要的三个参数——光圈、快门、ISO
注:这篇文章我四年前发布在其他地方,现在移过来. 如果你对相机只有很少了解,那么看这篇文章再好不过啦,我结合很多资料,力图用最通俗易懂的方式进行讲解. 相机拍摄时最重要的3个参数就是——光圈.快门.I ...