poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 4930 | Accepted: 1965 |
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
6
3 1
2 5
2 3
3 2
4 1
1 6
Sample Output
86
Hint
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<stack>
#include<map>
#include<string>
#define LL long long
using namespace std;
struct Node{
LL x, y;
bool operator < (const Node &A) const{
return y*1.0/x*1.0 > A.y*1.0/A.x*1.0;
}
}node[];
int main(){
int n;
while(~scanf("%d", &n)){
memset(node, , sizeof(node));
LL sumx = , sumy = ;
for(int i = ; i < n; i++){
scanf("%lld%lld", &node[i].x, &node[i].y);
sumx += node[i].x;
sumy += node[i].y;
}
sort(node, node+n);
LL ans = ;
for(int i = ; i < n; i++){
ans += (sumy -= node[i].y) * node[i].x * 2.0;
}
printf("%lld\n", ans);
}
return ;
}
poj 3262 Protecting the Flowers的更多相关文章
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- poj 3262 Protecting the Flowers 贪心 牛吃花
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11402 Accepted ...
- poj -3262 Protecting the Flowers (贪心)
http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...
- poj 3262 Protecting the Flowers 贪心
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...
- POJ 3262 Protecting the Flowers 【贪心】
题意:有n个牛在FJ的花园乱吃.所以FJ要赶他们回牛棚.每个牛在被赶走之前每秒吃Di个花朵.赶它回去FJ来回要花的总时间是Ti×2.在被赶走的过程中,被赶走的牛就不能乱吃 思路: 先赶走破坏力大的牛假 ...
- POJ 3362 Protecting the Flowers
这题和金华区域赛A题(HDU 4442)是一样的做法. 对两个奶牛进行分析,选择两个奶牛总花费少的方式排序. bool cmp(const X&a,const X&b){ return ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
- 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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- Delphi基本类型--枚举 子界 集合 数组
[plain] view plain copy <strong>根据枚举定义集合 </strong> TMyColor = (mcBlue, mcRed); TMyColorS ...
- 如何使用PL/SQL Developer查看和杀掉session
http://jingyan.baidu.com/article/3ea51489eb65b152e61bba8b.html
- Odoo 8.0 new API 之Environment
""" An environment wraps data for ORM records: - :attr:`cr`, the current database cur ...
- 10.this关键字
①在类的方法定义中使用的this关键字代表使用该方法的对 象的引用 ②当必须指出当前使用方法的对象是谁时要使用this ③有时使用this处理方法中成员变量和参数重名的情况 ④this可以看做是一个变 ...
- 中國區的代理協議的韓國遊戲廠商PatiGames
“與阿裏巴巴簽署旗下游戲「突突三國」在中國區的代理協議的韓國遊戲廠商PatiGames決定與阿裏巴巴終止合作.”相信這條前不久報導的新聞,很多人並不陌生,但這背後其實並不像表面那樣簡單.早在今年4月P ...
- this和super的区别
this和super的区别 1.this和super都代表什么 * this:代表当前对象的引用,谁来调用我,我就代表谁 * super:本类当前对象的父类内存空间标识 2.this和super的使用 ...
- PHPExcel 使用笔记
获取sheet 有效效值行列数 $maxCell = $objWorksheet->getHighestRowAndColumn(); $data = $objWorksheet->ran ...
- python2.7安装PIL.Image模块
这是大家常用的两种安装方法 sudo pip install PIL pip install PIL --allow-external PIL --allow-unverified PIL 如果安装成 ...
- How to reset password for unknow root
1. Click "e" when entering the grub 2. Add option " init=/bin/sh" to linux line. ...
- UISprite(NGUI)扩展 图片镂空
NGUI 版本2.6.3 在做新手引导时,需要高亮特定UI元素,也就是加个黑色蒙板,然后在蒙版上显示这个UI元素,为了简单方便我扩展了下UISprite,来镂空指定空间. 分为2种,矩形和圆镂空,矩形 ...