首页 > 其他分享 >POJ 2976:Dropping tests 01 分数规划

POJ 2976:Dropping tests 01 分数规划

时间:2023-07-07 13:39:34浏览次数:41  
标签:tests 01 ch average Dropping test include your



Dropping tests


Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 12291

 

Accepted: 4293


Description


In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cumulative average is defined to be

POJ 2976:Dropping tests 01 分数规划_#include

.

Given your test scores and a positive integer k, determine how high you can make your cumulative average if you are allowed to drop any k of your test scores.

Suppose you take 3 tests with scores of 5/5, 0/1, and 2/6. Without dropping any tests, your cumulative average is 

POJ 2976:Dropping tests 01 分数规划_#include_02

. However, if you drop the third test, your cumulative average becomes 

POJ 2976:Dropping tests 01 分数规划_Memory_03

.

Input


The input test file will contain multiple test cases, each containing exactly three lines. The first line contains two integers, 1 ≤ n ≤ 1000 and 0 ≤ k < n. The second line contains n integers indicating ai for all i. The third line contains npositive integers indicating bi for all i. It is guaranteed that 0 ≤ ai ≤ bi ≤ 1, 000, 000, 000. The end-of-file is marked by a test case with n = k = 0 and should not be processed.


Output


For each test case, write a single line with the highest cumulative average possible after dropping k of the given test scores. The average should be rounded to the nearest integer.


Sample Input


3 15 0 25 1 6 4 2 1 2 7 9 5 6 7 9 0 0


Sample Output


83100


Hint


To avoid ambiguities due to rounding errors, the judge tests have been constructed so that all answers are at least 0.001 away from a decision boundary (i.e., you can assume that the average is never 83.4997).



POJ竟然用不了读入优化。。。努WA好多发

01分数规划裸题


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef double db;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
const db eps=1e-6;
const int N=1010;
int n,m;
db d[N],a[N],b[N];
db work(db x)
{
	for(int i=1;i<=n;i++)d[i]=a[i]-x*b[i];
	sort(d+1,d+n+1);db sum=0.0;
	for(int i=m+1;i<=n;i++)sum+=d[i];
	return sum;
} 
int main()
{
	while(scanf("%d%d",&n,&m),n||m)
	{
		for(int i=1;i<=n;i++)scanf("%lf",&a[i]);
		for(int i=1;i<=n;i++)scanf("%lf",&b[i]);
		db l=0.0,r=1.0;
		while(fabs(r-l)>eps)
		{
			db mid=(l+r)/2;
			if(work(mid)>0)l=mid;
			else r=mid;
		}
		printf("%.0lf\n",l*100);
	}
	return 0;
}
/*
3 1
5 0 2
5 1 6
4 2
1 2 7 9
5 6 7 9
0 0

83
100

*/




标签:tests,01,ch,average,Dropping,test,include,your
From: https://blog.51cto.com/u_16181403/6651985

相关文章

  • BZOJ 3942: [Usaco2015 Feb]Censoring KMP
    3942:[Usaco2015Feb]CensoringTimeLimit: 10Sec  MemoryLimit: 128MBSubmit: 476  Solved: 260[Submit][Status][Discuss]DescriptionFarmerJohnhaspurchasedasubscriptiontoGoodHooveskeepingmagazineforhiscows,sotheyhaveplentyofmateria......
  • BZOJ 3073: [Pa2011]Journeys 线段树优化最短路
    3073:[Pa2011]JourneysTimeLimit: 20Sec  MemoryLimit: 512MBSubmit: 243  Solved: 80[Submit][Status][Discuss]DescriptionSeter建造了一个很大的星球,他准备建造N个国家和无数双向道路。N个国家很快建造好了,用1..N编号,但是他发现道路实在太多了,他要一条条......
  • BZOJ 2730: [HNOI2012]矿场搭建 tarjan割点
    2730:[HNOI2012]矿场搭建TimeLimit: 10Sec  MemoryLimit: 128MBSubmit: 2010  Solved: 935[Submit][Status][Discuss]Description煤矿工地可以看成是由隧道连接挖煤点组成的无向图。为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口......
  • BZOJ 2427: [HAOI2010]软件安装 树形背包
    2427:[HAOI2010]软件安装TimeLimit: 10Sec  MemoryLimit: 128MBSubmit: 1275  Solved: 492[Submit][Status][Discuss]Description现在我们的手头有N个软件,对于一个软件i,它要占用Wi的磁盘空间,它的价值为Vi。我们希望从中选择一些软件安装到一台磁盘容量为M计算机......
  • BZOJ 2243: [SDOI2011]染色 树链剖分+线段树
    2243:[SDOI2011]染色TimeLimit: 20Sec  MemoryLimit: 512MBSubmit: 7623  Solved: 2855[Submit][Status][Discuss]Description给定一棵有n个节点的无根树和m个操作,操作有2类:1、将节点a到节点b路径上所有点都染成颜色c;2、询问节点a到节点b路径上的颜色段数量(连续......
  • BZOJ 1915: [Usaco2010 Open]奶牛的跳格子游戏 单调队列优化dp
    1915:[Usaco2010Open]奶牛的跳格子游戏TimeLimit: 4Sec  MemoryLimit: 64MBSubmit: 281  Solved: 110[Submit][Status][Discuss]Description奶牛们正在回味童年,玩一个类似跳格子的游戏,在这个游戏里,奶牛们在草地上画了一行N个格子,(3<=N<=250,000),编号为1..N......
  • BZOJ 1927: [Sdoi2010]星际竞速 费用流
    1927:[Sdoi2010]星际竞速TimeLimit: 20Sec  MemoryLimit: 259MBSubmit: 2344  Solved: 1442[Submit][Status][Discuss]Description10年一度的银河系赛车大赛又要开始了。作为全银河最盛大的活动之一,夺得这个项目的冠军无疑是很多人的梦想,来自杰森座α星的悠......
  • BZOJ 3996: [TJOI2015]线性代数 最大权闭合子图 最小割
    3996:[TJOI2015]线性代数TimeLimit: 10Sec  MemoryLimit: 128MBSubmit: 1499  Solved: 885[Submit][Status][Discuss]Description给出一个N*N的矩阵B和一......
  • BZOJ 2435: [Noi2011]道路修建 树的遍历-_-
    2435:[Noi2011]道路修建TimeLimit: 10Sec  MemoryLimit: 128MBSubmit: 3810  Solved: 1300[Submit][Status][Discuss]Description在W星球上有n个国家。为了各自国家的经济发展,他们决定在各个国家之间建设双向道路使得国家之间连通。但是每个国家的国王都很......
  • AT_bcu30_2019_qual_a 题解
    思路纯模拟题,给定N和P后,定义一个计数器sum,重复N次输入,每输入一次就判断P也就是子弹的能量是否≥每面墙的厚度x,如果是,就用P减去x,sum增加1,表示穿过了一面墙,否则跳出循环,输出sum。代码#include<iostream>usingnamespacestd;intmain(){intn,p,sum=0,......