Day3-D-Protecting the Flowers POJ3262
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
6
3 1
2 5
2 3
3 2
4 1
1 6
Sample Output
86
Hint
typedef long long LL;
const int maxm = ;
struct Node {
int T, D;
bool operator< (const Node &a) const {
return (a.D * 1.0) / a.T < D * 1.0 / T;
}
} Nodes[maxm];
int n;
LL times = , sum = ;
int main() {
scanf("%d", &n);
for (int i = ; i < n; ++i) {
scanf("%lld%d", &Nodes[i].T, &Nodes[i].D);
}
sort(Nodes, Nodes + n);
for(int i = ;i < n; ++i) {
sum += Nodes[i].D * times;
times += Nodes[i].T * ;
}
printf("%lld\n", sum);
return ;
}
Day3-D-Protecting the Flowers POJ3262的更多相关文章
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 493 So ...
- bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
- 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
随机推荐
- 人工智能、大数据、物联网、区块链,四大新科技PK,你更看好谁?
最近行业中备受关注并且非常火热的产业有哪些呢?小编这边总结了一下,一共有4个,分别是人工智能.大数据.物联网和区块链,这四种新科技也一直是蓄势待发,未来将引领新一代的科技成长,也会带给人类很多更方便快 ...
- SprintBoot学习(一)
Spring Boot是什么? 1. SpringBoot是一个框架,一种全新的编程规范,他的产生简化了框架的使用,所谓简化是指简化了Spring众多框架中所需的大量且繁琐的配置文件,所以 Sprin ...
- ISE主备注册和同步
Synchronize Primary and Secondary Cisco ISE Nodes You can make configuration changes to Cisco ISE on ...
- Robot Framework 使用【2】-- MAC系统搭建Robot Framework
前言 上一篇中讲述了如何在windows环境下搭建Robot Framework,发完帖后有几位小伙伴就私下留言有没有MAC版本的搭建过程,由于笔者MAC上是安装了旧版本的,经过笔者本周零碎时间的尝试 ...
- Java面向对象编程 -1.4
对象内存分析 对象实例化操作初步分析 Java之中类属于引用数据类型,引用数据类型最大的困难之处在于要进行内存的管理,同时在进行操作的时候也会有内存关系的变化. 所以本次针对于之前的程序的内存关系进行 ...
- docker运行安装mysql postgres
安装mysql [root@host1 ~]# docker images -a REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql 5.7 4d ...
- OpenThreads库学习
在看STM32资料中看到STM32WB系列“双核无线微控制器配备双核无线微控制器(MCU)配备Bluetooth® 5.OpenThread和ZigBee®3.0连接技术,同时兼备超低功耗性能“不知道 ...
- 【PAT甲级】1045 Favorite Color Stripe (30 分)(DP)
题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个 ...
- pytest框架,使用print在控制台输入
代码示例: import pytest@pytest.fixture(autouse=True,scope='session') #autouse=True,scope='session'def se ...
- 【转载】script命令使用
二.script命令简介当你在终端或控制台上工作时,你可能想记录下自己做了些什么.这种记录可以看成是保存了终端痕迹的文档.假设你跟一些Linux管理员同时在系统上干活.或者说你让别人远程到你的服务器. ...