博客
关于我
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 5.X 报错 ERROR 1193 (HY000): Unknown system variable ‘validate_password_length‘
查看>>
MySQL:MySQL执行一条SQL查询语句的执行过程
查看>>
Mysql:SQL性能分析
查看>>
mysql:SQL按时间查询方法总结
查看>>
MySQL:什么样的字段适合加索引?什么样的字段不适合加索引
查看>>
MySQL:判断逗号分隔的字符串中是否包含某个字符串
查看>>
MySQL:某个ip连接mysql失败次数过多,导致ip锁定
查看>>
MySQL:索引失效场景总结
查看>>
Mysql:避免重复的插入数据方法汇总
查看>>
MyS中的IF
查看>>
M_Map工具箱简介及地理图形绘制
查看>>
m_Orchestrate learning system---二十二、html代码如何变的容易
查看>>
M×N 形状 numpy.ndarray 的滑动窗口
查看>>
m个苹果放入n个盘子问题
查看>>
n = 3 , while n , continue
查看>>
n 叉树后序遍历转换为链表问题的深入探讨
查看>>
N!
查看>>
N-Gram的基本原理
查看>>
n1 c语言程序,全国青少年软件编程等级考试C语言经典程序题10道七
查看>>
Nacos Client常用配置
查看>>