博客
关于我
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
你可能感兴趣的文章
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
netty的HelloWorld演示
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty的网络框架差点让我一夜秃头,哭了
查看>>
Netty相关
查看>>
Netty简介
查看>>
Netty线程模型理解
查看>>
netty解决tcp粘包和拆包问题
查看>>
Netty速成:基础+入门+中级+高级+源码架构+行业应用
查看>>
Netty遇到TCP发送缓冲区满了 写半包操作该如何处理
查看>>