博客
关于我
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
你可能感兴趣的文章
Node.js 函数计算如何突破启动瓶颈,优化启动速度
查看>>
Node.js 切近实战(七) 之Excel在线(文件&文件组)
查看>>
node.js 初体验
查看>>
Node.js 历史
查看>>
Node.js 回调函数的原理、使用方法
查看>>
Node.js 在个推的微服务实践:基于容器的一站式命令行工具链
查看>>
Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
查看>>
Node.js 异步模式浅析
查看>>
node.js 怎么新建一个站点端口
查看>>
Node.js 文件系统的各种用法和常见场景
查看>>
Node.js 模块系统的原理、使用方式和一些常见的应用场景
查看>>
Node.js 的事件循环(Event Loop)详解
查看>>
node.js 简易聊天室
查看>>
Node.js 线程你理解的可能是错的
查看>>