其他分享
首页 > 其他分享> > 1020 月饼 (25分)

1020 月饼 (25分)

作者:互联网

#include <stdio.h>
struct STUFF
{
    double ku,price;
    double dan;
};
int main()
{
    int N,D;
    float income=0;
    struct STUFF stuff[1001];
    scanf("%d %d",&N,&D);
    int left=D;
    for(int i=0;i<N;i++)
        scanf("%lf",&stuff[i].ku);
    for(int i=0;i<N;i++)
    {
        scanf("%lf",&stuff[i].price);
        stuff[i].dan=stuff[i].price/stuff[i].ku;
    }
    
    struct STUFF tmp;
    for(int i=0;i<N-1;i++)
    {
        for(int j=0;j<N-1-i;j++)
        {
            if(stuff[j].dan<stuff[j+1].dan)
            {
                tmp=stuff[j];
                stuff[j]=stuff[j+1];
                stuff[j+1]=tmp;
                
            }
        }
    }
    for(int i=0;i<N;i++)
    {
        if(stuff[i].ku<left)
        {
            left-=stuff[i].ku;
            income+=stuff[i].price;
        }
        else if(stuff[i].ku==left)
        {
            income+=stuff[i].price;
            break;
        }
        else
        {
            income+=stuff[i].dan*left;
            break;
        }
    }
    printf("%.2f",income);
    return 0;
}

标签:25,1020,月饼,int,double,STUFF,main,struct
来源: https://www.cnblogs.com/QRain/p/12228732.html