zoukankan      html  css  js  c++  java
  • 北京信息科技大学第十一届程序设计竞赛(重现赛)H

    H andy和购物

    题目链接:https://ac.nowcoder.com/acm/contest/940/H

    题目描述

    andy要去市场买n件货物,每件货物的价格为ai。商家为了吸引顾客,给每个买N件货物的顾客一个折扣清单,清单上有N个小于1的小数bj表示折扣。对于每个折扣bj,由用户自行决定用它使哪个货物的价格变成bj * ai,并且只能用一次。
    andy想让你帮他算一下他最少的花费。


    输入描述:

    先输入一个正整数t,代表样例的组数。(1≤t≤10)

    对于每个样例:

    第一行,输入一个正整数n(1≤n≤1000)。

    第二行包含n个整数,第i个整数a[i]代表第i个商品的原价。(1≤a[i]≤1e9)

    第三行包含n个小数b[i],含义如题目描述。(0≤b[i]≤1)

    输出描述:

    对于每个样例,输出一个实数s,保留3位小数,表示最小的花费。
    示例1

    输入

    1
    5
    1 2 3 4 5
    0.1 0.2 0.3 0.4 0.5

    输出

    3.500

    思路:

    原价大的与折扣大的相乘,将其排序后相乘累加即可

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1005;
    struct node{
        int a;
        double zhe;
    }Node[1005];
    int main()
    {
     
        int t;
        cin>>t;
        while(t--)
        {
            int n;
            cin>>n;
            int x[maxn];
            double y[maxn];
            for(int i=0;i<n;i++)
                cin>>x[i];
            sort(x,x+n);
            for(int i=0;i<n;i++)
                Node[i].a=x[i];
            for(int i=0;i<n;i++)
                cin>>y[i];
            sort(y,y+n,greater<double>());
            for(int i=0;i<n;i++)
                Node[i].zhe=y[i];
            double sum=0.0;
            for(int i=0;i<n;i++)
               sum+=Node[i].a*Node[i].zhe;
            printf("%.3f
    ",sum);
        }
        return 0;
    }
  • 相关阅读:
    Study Plan The Twelfth Day
    Study Plan The Fifteenth Day
    Study Plan The Seventeenth Day
    Study Plan The Tenth Day
    Study Plan The Eighth Day
    Study Plan The Eleventh Day
    Study Plan The Sixteenth Day
    Study Plan The Thirteenth Day
    Study Plan The Fourteenth Day
    Study Plan The Ninth Day
  • 原文地址:https://www.cnblogs.com/Vampire6/p/11131713.html
Copyright © 2011-2022 走看看