zoukankan      html  css  js  c++  java
  • HDU 4882 ZCC Loves Codefires (贪心)

    ZCC Loves Codefires

    题目链接:

    http://acm.hust.edu.cn/vjudge/contest/121349#problem/B

    Description

    Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, called "Memset137".
    It was on Codefires(CF), an online competitive programming site, that ZCC knew Memset137, and immediately became his fan.
    But why?
    Because Memset137 can solve all problem in rounds, without unsuccessful submissions; his estimation of time to solve certain problem is so accurate, that he can surely get an Accepted the second he has predicted. He soon became IGM, the best title of Codefires. Besides, he is famous for his coding speed and the achievement in the field of Data Structures.
    After become IGM, Memset137 has a new goal: He wants his score in CF rounds to be as large as possible.
    What is score? In Codefires, every problem has 2 attributes, let's call them Ki and Bi(Ki, Bi>0). if Memset137 solves the problem at Ti-th second, he gained Bi-KiTi score. It's guaranteed Bi-KiTi is always positive during the round time.
    Now that Memset137 can solve every problem, in this problem, Bi is of no concern. Please write a program to calculate the minimal score he will lose.(that is, the sum of Ki*Ti).

    Input

    The first line contains an integer N(1≤N≤10^5), the number of problem in the round.
    The second line contains N integers Ei(1≤Ei≤10^4), the time(second) to solve the i-th problem.
    The last line contains N integers Ki(1≤Ki≤10^4), as was described.

    Output

    One integer L, the minimal score he will lose.

    Sample Input

    3
    10 10 20
    1 2 3

    Sample Output

    150

    Hint

    Memset137 takes the first 10 seconds to solve problem B, then solves problem C at the end of the 30th second. Memset137 gets AK at the end of the 40th second.
    L = 10 * 2 + (10+20) * 3 + (10+20+10) * 1 = 150.


    ##题意: 在时间t解决第i个问题,会损失ki*t分数: 给出每个题的ki和所需时间,求解决所有问题的最小损失.
    ##题解: 先解决每分钟扣分最多的.
    对于可能要排序的题,考虑相邻元素的交换对结果造成的影响来得出排序条件.
    考虑任意相邻两题i,j,交换前后的损失之差为: e[i]*k[i]+(e[i]+e[j])*k[j] - (e[i]+e[j])*k[i]+e[j]*k[j] 要使得上式小于零成立的条件为:e[i]*k[j] < e[j]*k[i] 以此为标准进行排序即可.

    ##代码: ``` cpp #include #include #include #include #include #include #include #include #include #define LL long long #define eps 1e-8 #define maxn 101000 #define mod 100000007 #define inf 0x3f3f3f3f #define IN freopen("in.txt","r",stdin); using namespace std;

    int n;
    struct node {
    int t,k;
    double per;
    bool operator < (const node & b) const {
    return per < b.per;
    }
    }num[maxn];

    int main(int argc, char const *argv[])
    {
    //IN;

    while(scanf("%d", &n) != EOF)
    {
        for(int i=1; i<=n; i++)
            scanf("%d", &num[i].t);
        for(int i=1; i<=n; i++)
            scanf("%d", &num[i].k);
        for(int i=1; i<=n; i++)
            num[i].per = (double)(num[i].t) / (double)(num[i].k);
    
        sort(num+1, num+1+n);
    
        LL ans = 0;
        LL curt = 0;
        for(int i=1; i<=n; i++) {
            curt += (LL)(num[i].t);
            ans += curt * (LL)(num[i].k);
        }
    
        printf("%I64d
    ", ans);
    }
    return 0;
    

    }

  • 相关阅读:
    无线渗透开启WPS功能的路由器
    写代码怎能不会这些Linux命令?
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    每天进步一点点——五分钟理解一致性哈希算法(consistent hashing)
    Innodb 中的事务隔离级别和锁的关系
    线上操作与线上问题排查实战
    MySQL 四种事务隔离级的说明
    一次由于 MTU 设置不当导致的网络访问超时
    SYN 和 RTO
    The story of one latency spike
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5719140.html
Copyright © 2011-2022 走看看