http://acm.hdu.edu.cn/showproblem.php?pid=4882

ZCC Loves Codefires

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 97    Accepted Submission(s): 55

Problem 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-Ki*Ti score. It's guaranteed Bi-Ki*Ti 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.


 分析:
1.x1y1+(x1+x2)*y2->x1*y1+x1*y2+x2*y2
2.x2*y2+(x1+x2)*y1->x1*y1+x2*y1+x2*y2
由此可以看出只要x1*y2<=x2*y1即可,每2项对前后没什么关系。推出一般规则是:aj*ai≤ai*aj。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
}a[100005];
bool cmp(node b,node c)
{
return b.x*c.y<=b.y*c.x;
}
int main()
{
int n,i;
__int64 ans,cnt;
while(~scanf("%d",&n))
{
for(i=0;i<n;i++)
scanf("%d",&a[i].x);
for(i=0;i<n;i++)
scanf("%d",&a[i].y);
sort(a,a+n,cmp);
ans=cnt=0;
for(i=0;i<n;i++)
{
cnt+=a[i].x;
ans+=cnt*a[i].y;
}
printf("%I64d\n",ans);
}
return 0;
}
 

HDU-4882 ZCC Loves Codefires的更多相关文章

  1. hdu 4882 ZCC Loves Codefires(数学题+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...

  2. HDU 4882 ZCC Loves Codefires (贪心)

    ZCC Loves Codefires 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/B Description Though ...

  3. HDU 4882 ZCC Loves Codefires(贪心)

     ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. 2014多校第二场1011 || HDU 4882 ZCC Loves Codefires (贪心)

    题目链接 题意 : 给出n个问题,每个问题有两个参数,一个ei(所要耗费的时间),一个ki(能得到的score).每道问题需要耗费:(当前耗费的时间)*ki,问怎样组合问题的处理顺序可以使得耗费达到最 ...

  5. hdu 4882 ZCC Loves Codefires (贪心 推导)

    题目链接 做题的时候凑的规律,其实可以 用式子推一下的. 题意:n对数,每对数有e,k, 按照题目的要求(可以看下面的Hint就明白了)求最小的值. 分析:假设现在总的是sum, 有两个e1 k1 e ...

  6. hdu 4882 ZCC Loves Codefires(贪心)

    # include<stdio.h> # include <algorithm> # include <string.h> using namespace std; ...

  7. 2014---多校训练2(ZCC Loves Codefires)

    ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. HDU 4876 ZCC loves cards(暴力剪枝)

    HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...

  9. hdu 4873 ZCC Loves Intersection(大数+概率)

    pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...

随机推荐

  1. C# get set方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. 套题T8&T9

    A - 8球胜负(eight) Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Submi ...

  3. lintcode 中等题:Min stack 最小栈

    题目 带最小值操作的栈 实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值. 你实现的栈将支持push,pop 和 min 操作,所有操作要求都在O(1)时间内完成. 解题 可以定义 ...

  4. 解决Eclipse10配置Pydev不成功的问题

    本人在线配置还在本地配置后 重启Eclipse,Windows-Preferences中并无Python选项,新建项目也无Python可选 这个尝试了好多种方法,重新安装Eclipse10,重新安装j ...

  5. 关于fisher判别的一点理解

    最近一个朋友问这方面的一些问题,其实之前也就很粗略的看了下fisher,真正帮别人解答问题的时候才知道原来自己也有很多东西不懂.下面小结下自己对fisher判别的理解: 其实fisher和PCA差不多 ...

  6. Java学习笔记之:Java流程控制

    一.介绍 Java流程控制包括顺序控制.条件控制和循环控制. 顺序控制,就是从头到尾依次执行每条语句操作.条件控制,基于条件选择执行语句,比方说,如果条件成立,则执行操作A,或者如果条件成立,则执行操 ...

  7. 常用Shell的路径

    #define REG_SHELL "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\S ...

  8. IOSSelector的用法

    1.首先,@selector 里面的方法不能传参数..不要相信网上的..都是复制粘贴的.2.分三步走:1.设置tag.2.设置btn的调用方法.3.使用参数2.看示例代码把..   UIButton ...

  9. 面试题_17_to_30_数据类型和 Java 基础面试问题

    17)Java 中应该使用什么数据类型来代表价格?(答案)如果不是特别关心内存和性能的话,使用BigDecimal,否则使用预定义精度的 double 类型. 18)怎么将 byte 转换为 Stri ...

  10. truncate table 和delete

    delete table 和 truncate table 使用delete语句删除数据的一般语法格式: delete [from] {table_name.view_name} [where< ...