题意:给出n门课程,每一门课程考的分数,每一门课程的学分,求最多删去k组数据之后能够得到的最大加权平均数

先开一个数组x[],其中x[i]=1代表没有删除这门课程,x[i]=0表示删除了这门课程

然后p[i]=R*c[i]-c[i]*s[i]=c[i]*(R-s[i])

又因为满分为100分,就在0.0在100.0二分来找 再将p数组降序排列,ans为其前n-k个数的和, 如果ans-0>eps,那么l=mid, 如果ans-0<eps,那么r=mid

因为p[]数组是按照降序排列的,所以ans应该是递减的,大概是像这幅图一样

貌似这样理解有问题,再想一想先-----

下面是学习的代码---------------

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
double eps=1e-; int s[maxn],c[maxn];
double p[maxn]; bool cmp(double a,double b){
return a>b;
} int main(){
int ncase;
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
scanf("%d",&ncase);
for(int t=;t<=ncase;t++){
int n,k;
scanf("%d %d",&n,&k);
for(int i=;i<=n;i++) scanf("%d",&s[i]);
for(int i=;i<=n;i++) scanf("%d",&c[i]); double l=0.0,r=100.0,mid; while((r-l)>eps){
mid=(l+r)/; for(int i=;i<=n;i++) p[i]=(double)c[i]*(double)(s[i]-mid); sort(p+,p+n+,cmp); double ans=0.0;
for(int i=n-k;i>=;i--) ans+=p[i]; if(ans->eps) l=mid;
else r=mid;
} printf("Case #%d:\n",t);
printf("%.3lf\n",mid);
}
return ;
}

最新文章

  1. Linux_函数使用手册(中、英),确实不错
  2. Maltego实体分类与Transform
  3. 形状特征提取-Hu不变矩(转载)
  4. 30个实例详解TOP命令
  5. UI1_应用的程序的生命周期
  6. 385. Mini Parser
  7. js获取ip方法
  8. HDOJ(HDU) 1563 Find your present!(异或)
  9. SWOT自我分析
  10. mit java open course assignment #2
  11. thenjs的应用
  12. IOS开发创建开发证书及发布App应用(二)——创建证书
  13. css3毛玻璃模糊效果
  14. 【转】awk 里的substr函数用法举例
  15. C#--深入理解类型
  16. netcore项目在Centos部署:nohup和supervisor方式
  17. Kafka 详解(三)------Producer生产者
  18. Android学习之基础知识五—创建自定义控件
  19. 解决VS2010连接VSS时,Access to file&quot;\\***\rights.dat&quot; denied
  20. u-boot.lds文件简介

热门文章

  1. 深入理解jQuery的Event机制
  2. UNITY_MATRIX_IT_MV[Matrix] (转载)
  3. VSync Count 垂直同步
  4. lof基金
  5. tar命令--解压缩
  6. Windows Server
  7. iOS block示例
  8. C# 给数据库传入当前时间
  9. WCF分布式开发步步为赢(9):WCF服务实例激活类型编程与开发
  10. CyclicBarrier、CountDownLatch与Semaphore的小记