POJ 2976 Dropping tests
来源:互联网 发布:windows nt4.0下载 编辑:程序博客网 时间:2024/06/11 08:06
大意不再赘述。
0/1分数规划,关键在于了解二分枚举时得到的ans值不是最终值,自身枚举的mid值才是。了解通过函数的单调性,凹性,构造出Q(L) = cx - L* x dx 得到原问题的子问题,然后通过二分枚举或者其他的方法求得解。
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;const int MAXN = 1010;const double eps = 1e-4;struct node{double x, y;}a[MAXN];int n, k;int read_case(){scanf("%d%d", &n, &k);if(!n && !k) return 0;for(int i = 0; i < n; i++) scanf("%lf", &a[i].x);for(int i = 0; i < n; i++) scanf("%lf", &a[i].y);return 1;}double build(double mid){double t[MAXN] = {0};double ans = 0;for(int i = 0; i < n; i++){t[i] = a[i].x - mid*a[i].y;}sort(t, t+n, greater<double> ()); //用了sort之后,如果是从1开始输入的,那么排序之后下标变为0。 for(int i = 0; i < n-k; i++){ans += t[i];}return ans;}void solve(){double x = 0, y = 1.0;while(y-x > eps){double mid = x+(y-x)/2;if(build(mid) > 0) x = mid;else y = mid;}printf("%.f\n", x*100);}int main(){while(read_case()){solve();}return 0;}
- poj 2976 Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- poj 2976-Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- POJ-2976-Dropping tests
- poj 2976 Dropping tests
- POJ 2976 Dropping tests
- Poj 2976 Dropping tests
- POJ-2976Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- POJ 2976 Dropping tests
- Dropping tests - POJ 2976 二分
- poj 2976 Dropping tests,二分
- POJ 2976 Dropping tests 01分数规划
- POJ 2976 Dropping tests 01分数规划
- LINUX下GCC编译sqrt函数问题
- Netstat命令详解(windows)
- BeanUtils介绍
- jpa中的继承层次结构
- How to Use FxCop
- POJ 2976 Dropping tests
- js判断键盘按键
- 文件操作初体验
- Flex 页面空白或Error #2032: 流错误处理解决办法
- Windows Phone 8 新篇章(1):先把牛皮吹破
- 如何:使用命令行创建和使用程序集(C# 和 Visual Basic)
- 黑马程序员_JAVA_面向对象(一)
- vs2008 下使用ICE 的Hello world 程序
- XsqlFilterResult----动态生成sql语句的类,过滤一些为空的查询条件