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 ...
随机推荐
- How to Pronounce the Word SOMETHING
How to Pronounce the Word SOMETHING Share Tweet Share Something tells me you’re going to like this v ...
- Access-Control-Allow-Origin与跨域
文章转载地址: http://freewind.me/blog/20140327/2456.html 问题 在某域名下使用Ajax向另一个域名下的页面请求数据,会遇到跨域问题.另一个域名必须在resp ...
- 迷你MVVM框架 avalonjs 1.3.6发布
本版本是一次重要的升级,考虑要介绍许多东西,也有许多东西对大家有用,也发到首页上来了. 本来是没有1.36的,先把基于静态收集依赖的1.4设计出来后,发现改动太多,为了平缓升级起见,才减少了一部分新特 ...
- servlet和JSP页面乱码问题
JSP和Servlet的中文乱码处理 前几天学习了JSP和Servlet中有关中文乱码的一些问题,写成了博客,今天进行更新一下.应该是可以解决日常的乱码问题了.现在作以下总结希望对需要的人有所帮助.我 ...
- 开始一个Android的appium实例
1.查看Android的应用包名和activity的方法 (网上有很多种方法,这里应用的是查看日志的方法) CMD中输入>adb logcat -c ...
- Android中MD5加密
最近项目中遇到MD5加密,代码很简单,又是死代码,不过要注意当长度不足32的时候要补个0.下面是具体代码,直接拷贝就能用. public static String getMD5(String str ...
- Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...
- strcpy函数;memcpy函数;memmove函数
strcpy函数实现: char* strcpy(char* des,const char* source) { char* r=des; assert((des != NULL) && ...
- Excel日期格式调整
3-Aug-2008 自定义格式: [$-809]d-mmm-yyyy;@ Aug-2008 自定义格式: [$-809]mmm-yyyy;@
- nginx 反向代理 apache 服务
反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时 ...
.
. However, if you drop the third test, your cumulative average becomes
.