题目意思能搞成这样我也是服了这个女人了

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm> using namespace std; int main() {
int N = ;
double D = ;
scanf("%d%lf", &N, &D);
vector<pair<double, double> > base(N);
vector<double> amount(N);
vector<double> price(N);
double tmp;
for (int i=; i<N; i++) {
scanf("%lf", &amount[i]);
}
for (int i=; i<N; i++) {
scanf("%lf", &price[i]);
base[i].first = amount[i] / price[i];
base[i].second= i;
} sort(base.begin(), base.end()); double cur = ;
double mon = ;
int i = ; while(cur < D && i < N) {
int idx = base[i].second;
double use = amount[idx];
if ((use + cur) >= D) use = D - cur;
mon += use / amount[idx] * price[idx];
cur += use;
i++;
}
printf("%.2lf", mon);
return ;
}

PAT 1070 Mooncake的更多相关文章

  1. PAT 1070 Mooncake[一般]

    1070 Mooncake (25)(25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Aut ...

  2. PAT 1070. Mooncake (25)

    Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival.  Many types ...

  3. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  4. 1070 Mooncake (25 分)

    1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn ...

  5. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  6. PAT Advanced 1070 Mooncake (25) [贪⼼算法]

    题目 Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many typ ...

  7. PAT (Advanced Level) 1070. Mooncake (25)

    简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vecto ...

  8. PAT甲题题解-1070. Mooncake (25)-排序,大水题

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. 1070. Mooncake (25)

    题目如下: Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many ...

随机推荐

  1. loj #2051. 「HNOI2016」序列

    #2051. 「HNOI2016」序列 题目描述 给定长度为 n nn 的序列:a1,a2,⋯,an a_1, a_2, \cdots , a_na​1​​,a​2​​,⋯,a​n​​,记为 a[1: ...

  2. [Swift实际操作]九、完整实例-(2)在Xcode 10中创建新项目

    本文将在Xcode中创建上一文<在iTunesConnect网站中创建产品>在iTunes Connect创建的产品具有相同的Bundle ID的应用程序. 在项目模板窗口中,选择单视图模 ...

  3. 如何查看Centos版本

    使用命令 cat /etc/centos-release 查看效果如下图 当然,你也可以查看红帽的版本 cat /etc/redhat-release 郴州软件开发培训 郴州软件培训 郴州java培训 ...

  4. jquery.from帮助类

    /** * 将form里面的内容序列化成json * 相同的checkbox用分号拼接起来 * @param {obj} 需要拼接在后面的json对象 * @method serializeJson ...

  5. 移动端适配1px问题

    (function(document) { var dcl = document.documentElement, wh; var scale = 1/window.devicePixelRatio; ...

  6. 用IDM下载博客图片

    前言 写博客的人一定都会有一个图床,将图片存在那里.发现自己以前没有注意图片来源问题,随手就贴在博客上面了.现在有不少图片都挂了,换句话来说有可能自己目前用的图床不提供服务了,那所有的图片都有可能丢失 ...

  7. 记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration

    今天遇到的一个问题: 代码检查了好几次,都没有错误,但是启动时就会报错Consider defining a bean of type ''' in your configuration. 启动类在c ...

  8. Luogu P1272 重建道路 树形DP

    刚才瞅了半天自己当初写的,终于瞅出来了...QWQ 设f[i][j]表示以i为根的子树,包含j个节点所需砍掉的最小边数 那么可知f[u][1]=u的度: 方程:f[u][j]=min(f[u][j], ...

  9. LeetCode934.shortest bridge【dfs+bfs】

    一.题面 在给定的二维二进制数组 A 中,存在两座岛.(岛是由四面相连的 1 形成的一个最大组.) 现在,我们可以将 0 变为 1,以使两座岛连接起来,变成一座岛. 返回必须翻转的 0 的最小数目.( ...

  10. QDU_AP协会18级ST1

    A - A + B Problem II I have a very simple problem for you. Given two integers A and B, your job is t ...