博客
关于我
POJ2976 Dropping tests (最大化平均值/二分)
阅读量:184 次
发布时间:2019-02-28

本文共 769 字,大约阅读时间需要 2 分钟。

问题描述:

这里写图片描述

这个题目,典型的最大化平均值,依然是水题,但是因为一些细节,导致提交好几次都wa。

细节:

1.题目是drop k 个,所以最后转换一下思想(和牛过河搬石子是一样的),在n个里选n-k个,则相当于drop k 个。
2.题目要求the average should be rounded to the nearest integer,就因为这个,wa了几次没发现。

代码如下:

#include
#include
using namespace std;const int maxn = 1000+10;const int INF = 1000000000;int a[maxn],b[maxn];double y[maxn];int n,k;bool C(double d){ for(int i=0; i
= 0;}void solve(){ double lb = 0, ub = INF; for(int i=0; i<100; i++) { double mid = (lb + ub) / 2; if(C(mid)) lb = mid; else ub = mid; } double p = 100 * lb; int q; if((int)(p + 0.5) > (int)p) q = (int)p + 1;//关键细节 else q = (int)p; printf("%d\n",q);}int main(){ while(scanf("%d%d",&n, &k)==2 && n) { for(int i=0; i
你可能感兴趣的文章
mysql函数汇总之数学函数
查看>>
mysql函数汇总之日期和时间函数
查看>>
mysql函数汇总之条件判断函数
查看>>
mysql函数汇总之系统信息函数
查看>>
MySQL函数简介
查看>>
mysql函数遍历json数组
查看>>
MySQL函数(转发)
查看>>
mysql分区表
查看>>
MySQL分层架构与运行机制详解
查看>>
mysql分库分表中间件简书_MySQL分库分表
查看>>
MySQL分库分表会带来哪些问题?分库分表问题
查看>>
MySQL分组函数
查看>>
MySQL分组查询
查看>>
Mysql分表后同结构不同名称表之间复制数据以及Update语句只更新日期加减不更改时间
查看>>
mySql分页Iimit优化
查看>>
MySQL分页查询
查看>>
WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 Selenium 的 Chrome 二进制错误
查看>>
mysql列转行函数是什么
查看>>