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

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

using namespace std;
/*
3 0
180 150 100
7.5 7.2 4.5
*/
const int maxn=1000+5;
int amounts[maxn];
float price[maxn];

struct Cake{
    float amounts;  //注意,这里得设置成浮点型,若是int一个样例会过不了
    float price;
    float unitprice=0;
    bool operator<(const Cake tmp)const{
        return unitprice>tmp.unitprice;
    }
}cake[maxn];
int main()
{
    int n,d;
    scanf("%d %d",&n,&d);
    for(int i=0;i<n;i++){
        scanf("%f",&cake[i].amounts);
    }
    for(int i=0;i<n;i++){
        scanf("%f",&cake[i].price);
        cake[i].unitprice=cake[i].price/cake[i].amounts;
    }
    sort(cake,cake+n);
    float ans=0;
    for(int i=0;i<n;i++){
        if(d>=cake[i].amounts){
            ans+=cake[i].price;
            d-=cake[i].amounts;
        }
        else{
            ans+=(d/cake[i].amounts)*cake[i].price;
            break;
        }
    }
    printf("%.2f",ans);
    return 0;
}

时间: 2024-10-13 09:10:01

PAT甲题题解-1070. Mooncake (25)-排序,大水题的相关文章

PAT 1070. Mooncake (25)

Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival.  Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture.  Now given the inventory amounts and the prices of al

PAT甲题题解-1012. The Best Rank (25)-排序水题

排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询,建立id与索引的映射即可. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <map> using namespace s

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

题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润.输出最大利润. trick: 测试点2可能包含M不为整数的数据.(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数.....) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using names

PAT甲题题解-1050. String Subtraction (20)-水题

#include <iostream> #include <cstdio> #include <string.h> #include <algorithm> using namespace std; /* 水题,注意字符范围是整个ASCII编码即可. */ const int maxn=130; int vis[maxn]; char s1[10000+5]; char s2[10000+5]; int main() { gets(s1); //getcha

PAT (Advanced Level) 1070. Mooncake (25)

简单贪心.先买性价比高的. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; double eps=1e-7

PAT:1070. Mooncake (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct moomcake { double store; //[cation]这个可能是小数! double sumPrice; double solePrice; }M[1010]; bool cmp(moomcake a,moomcake b) { return a.solePrice>b.soleP

1070. Mooncake (25)

(库存量也是double) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes accordi

pat1070. Mooncake (25)

1070. Mooncake (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes a

Pythagorean Triples CodeForces - 707C 推理题,大水题

给定一个数n(1 <= n <= 1e9),判断这个数是否是一个直角三角形的边长,如果是,则输出另外两条边(1 <= x <= 1e18),否则输出-1. 参考题解:http://blog.csdn.net/harlow_cheng/article/details/69055614 首先,当n <= 2 的时候无解,其他时候都有解 假设n是直角边,a是斜边,则n^2 + b^2 = a^2; n^2 = (a + b)*(a - b); ①假设n是偶数,则另(a - b) =