pat_b_1020 月饼

      http://pat.zju.edu.cn/contests/pat-b-practise/1020


      分析: 贪心——按单价大者优先;

                   注意: 月饼库存量为int数据类型时,有一组数据不能通过;改为double,AC


       代码:

                  

//月饼
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int maxn=1002;

struct node
{
    double num;
    double price;
    double v;
}a[maxn];

int cmp(node x, node y)
{
    return x.v - y.v > 0.000001;
}

int main()
{
    freopen("in.txt","r",stdin);

    int n,w;
    double ans=0;
    scanf("%d%d",&n,&w);
    for(int i=0;i

你可能感兴趣的:(pat_b,pat_b)