PAT1070. Mooncake (25)
#include
#include
#include <stdio.h>
#include <math.h>
using namespace std;
struct SS{
double s;
double p;
double si;
};
int n,d;
SS pro[1010];
bool cmp(const SS &a,const SS &b){
return a.si>b.si;
}
int main(){
cin>>n>>d;
for(int i=0;i<n;i++) cin>>pro[i].s;
for(int i=0;i<n;i++) {
cin>>pro[i].p;
if(fabs(pro[i].s)<1e-9){
pro[i].si=0;
}else pro[i].si=pro[i].p/pro[i].s;
}
sort(pro,pro+n,cmp);
int i=0;
double res=0;
while(d&&i<n){
if(pro[i].s<d){
d-=pro[i].s;
res+=pro[i].p;
i++;
}else{
res+=pro[i].si*d;
d=0;
}
}
printf("%.2f\n",res);
return 0;
}
PAT1070. Mooncake (25)的更多相关文章
- PAT1070:Mooncake
1070. Mooncake (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mooncake is ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 1070. Mooncake (25)
Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types ...
- 1070. Mooncake (25)
题目如下: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many ...
- PAT Advanced 1070 Mooncake (25) [贪⼼算法]
题目 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many typ ...
- PAT (Advanced Level) 1070. Mooncake (25)
简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...
- PAT甲题题解-1070. Mooncake (25)-排序,大水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- A1070 Mooncake (25 分)
一.参考代码 #include<cstdio> #include<algorithm> #include<iostream> using namespace std ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
随机推荐
- PDO 指南
简介 前面咱已经见过MySQLi了,现在咱一起来看看PDO类.PDO是PHP Data Objects的缩写,它被描述为“在PHP中访问数据库的轻量级,兼容性的接口”.尽管它的名字不咋好听,但PDO是 ...
- add() 方法用于向 <select> 添加一个 <option> 元素。
//add() 方法用于向 <select> 添加一个 <option> 元素. //new Option() 创建一个option标签 school.add(new Opti ...
- Linux命令:tac
全称:concatenate and print files in reverse 用途:将文件全部内容从尾到头反向连续输出到标准输出(屏幕)上 格式:tac [OPTION]... [FILE].. ...
- Git查看、删除远程分支和tag
本站文章除注明转载外,均为本站原创或者翻译. 本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商: 本站部分原创和翻译文章提供markdown格式源码,欢迎使 ...
- jQuery中this与$(this)的差别
jQuery中this与$(this)的差别 $("#textbox").hover( function() { this.title ...
- .NET加密方式解析--散列加密
在现代社会中,信息安全对于每一个人都是至关重要的,例如我们的银行账户安全.支付宝和微信账户安全.以及邮箱等等,说到信息安全,那就必须得提到加密技术,至于加密的一些相关概念,在这里就不说了. 这一次将会 ...
- 005-hive概述,计算原理及模型
计算原理及模型 优化的根本思想: 尽早尽量过滤数据,减少每个阶段的数据量 减少job数 解决数据倾斜问题 Hive概述 名称 hive系统架构 metastore derbymysql ...
- 机器学习算法(优化)之一:梯度下降算法、随机梯度下降(应用于线性回归、Logistic回归等等)
本文介绍了机器学习中基本的优化算法—梯度下降算法和随机梯度下降算法,以及实际应用到线性回归.Logistic回归.矩阵分解推荐算法等ML中. 梯度下降算法基本公式 常见的符号说明和损失函数 X :所有 ...
- jQery实现插入删除信息
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- kettle中的karaf设置
Spoon.sh设置-Dpentaho.karaf.root.copy.dest.folder=$PENTAHO_KARAF_ROOT -Dpentaho.karaf.root.transient=f ...