POJ 3262 Protecting the Flowers(贪心,需要小小优化一下)
来源:互联网 发布:ubuntu 安装打印机 编辑:程序博客网 时间:2024/04/30 06:46
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 5692
Accepted: 2237
Description
Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his horror that the cluster of cows was in his garden eating his beautiful flowers. Wanting to minimize the subsequent damage, FJ decided to take immediate action and transport each cow back to its own barn.
Each cow i is at a location that is Ti minutes (1 ≤ Ti ≤ 2,000,000) away from its own barn. Furthermore, while waiting for transport, she destroys Di (1 ≤ Di ≤ 100) flowers per minute. No matter how hard he tries, FJ can only transport one cow at a time back to her barn. Moving cow i to its barn requires 2 × Ti minutes (Ti to get there and Ti to return). FJ starts at the flower patch, transports the cow to its barn, and then walks back to the flowers, taking no extra time to get to the next cow that needs transport.
Write a program to determine the order in which FJ should pick up the cows so that the total number of flowers destroyed is minimized.
Input
Lines 2..N+1: Each line contains two space-separated integers, Ti and Di, that describe a single cow's characteristics
Output
Sample Input
63 12 52 33 24 11 6
Sample Output
86
Hint
#include<cstdio>#include<cstring>#include<algorithm>#define ll __int64using namespace std;ll sum[100010];struct node{ll t,d; }cow[100010];int cmp(node a,node b){return (a.t*1.0/a.d)<(b.t*1.0/b.d);} int main(){int n,i,j;ll ans;while(scanf("%d",&n)!=EOF){for(i=0;i<n;++i)scanf("%I64d%I64d",&cow[i].t,&cow[i].d);sort(cow,cow+n,cmp);sum[n-1]=0;for(i=n-2;i>=0;i--)sum[i]=sum[i+1]+cow[i+1].d;ans=0;for(i=0;i<n;++i)ans+=2*cow[i].t*sum[i];printf("%I64d\n",ans);}return 0;}
- POJ 3262 Protecting the Flowers(贪心,需要小小优化一下)
- POJ 3262 Protecting the Flowers (贪心 + 优化)
- POJ 3262 Protecting the Flowers 贪心
- poj 3262 Protecting the Flowers (贪心)
- poj 3262 Protecting the Flowers(贪心)
- poj 3262 Protecting the Flowers 【贪心】
- poj 3262 Protecting the Flowers(贪心)
- Protecting the Flowers - POJ 3262 贪心
- poj 3262 Protecting the Flowers(贪心)
- POJ 3262 Protecting the Flowers【贪心】
- POJ 3262 - Protecting the Flowers(贪心)
- POJ 3262 Protecting the Flowers (贪心)
- POJ 3262 Protecting the Flowers(贪心)
- POJ 3262 Protecting the Flowers(贪心)
- Poj 3262 Protecting the Flowers【贪心】
- POJ 3262 Protecting the Flowers 贪心
- 【贪心】POJ 3262 Protecting the Flowers
- *Protecting the Flowers(POJ 3262, 贪心)
- 2015年,关于品牌经营的收获
- 常用的sql语句
- delete释放new[]造成的泄漏
- 如何成为顶级技术巨匠?
- ACM、蓝桥杯等程序竞赛中的一些经验-0
- POJ 3262 Protecting the Flowers(贪心,需要小小优化一下)
- 概率专题·期望
- 嵌入式STMFD SP!,{R0-R7,LR}分析
- Matlab笔记-0
- C语言 数组长度...int length = sizeof(stu) / sizeof(stu[0]);
- 学校里的那首歌
- java温习笔记01:环境配置及编辑器设置
- [c语言]EmailAddresses(for hw)
- 黑马程序员——阶乘的两种实现方法及水仙花数的打印