【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers
直接中文
Descriptions
FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草。当他回来的时候,他发现奶牛们正在津津有味地吃着FJ种的美丽的花!为了减少后续伤害,FJ决定立即采取行动:运输每头牛回到自己的牛棚。 每只奶牛i在离牛棚Ti(1 ≤ Ti ≤ 2,000,000) 分钟路程的地方,每分钟吃掉Di(1 ≤ Di ≤ 100)朵花。FJ使尽浑身解数,也只能一次带回一头奶牛。弄回一头奶牛i需要2*Ti分钟(来回)。由于怕被怼,从FJ决定带回i号奶牛开始,i号奶牛就不会吃花。请你找出被毁坏的花的最小数量 .
Input
第 2.. N+1: 第i+1行是Ti和Di,
Output
Sample Input
6
3 1
2 5
2 3
3 2
4 1
1 6
Sample Output
86
Hint
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100000+100
using namespace std;
int n;
struct node
{
int t;//时间
int d;//破坏力
};
node a[Maxn];
bool cmp(node x,node y)
{
// 破坏力/时间,易得谁的破坏力大,先送破坏力大的回家
double t1=(x.d*1.0)/(x.t*1.0);
double t2=(y.d*1.0)/(y.t*1.0);
return t1>t2;
}
int main()
{
cin>>n;
// 题目强调了结果在64位整数范围内,注意用ll
ll sum=;//全部破坏的花朵数量
ll ans=;//最终答案
for(int i=; i<n; i++)
{
cin>>a[i].t>>a[i].d;
sum+=a[i].d;
}
sort(a,a+n,cmp);//按破坏力从大到小排序
// 排序结果
// for(int i=0;i<n;i++)
// cout<<a[i].t<<" "<<a[i].d<<endl;
for(int i=; i<n-; i++)
{
sum-=a[i].d;//送哪个走,哪个破坏的花朵数量就不能计算在内,其他的都要乘上这头牛的时间再*2
ans+=sum*a[i].t*;
}
cout<<ans<<endl;
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
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 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 ...
- POJ3262 Protecting the Flowers 【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4418 Accepted: ...
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...
随机推荐
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)
题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Luogu P1951 收费站_NOI导刊2009提高(2) 二分 最短路
思路:二分+最短路 提交:1次 题解: 二分最后的答案. $ck()$: 对于每次的答案$md$跑$s,t$的最短路,但是不让$c[u]>md$的点去松弛别的边,即保证最短路不经过这个点.最后$ ...
- ege图形库之简单贪吃蛇(c++)
第二次做动画显示效果的小程序,心血来潮想做下儿时的经典游戏----贪吃蛇.由于时间有限,只是简单地做了基本功能,有时间后再完善更多功能. 由于个人水平有限,可能代码有些地方可以改进.不足之处敬请指出. ...
- 使用Spring基于应用层实现读写分离(一)基础版
背景 我们一般应用对数据库而言都是“读多写少”,也就说对数据库读取数据的压力比较大,有一个思路就是说采用数据库集群的方案, 其中一个是主库,负责写入数据,我们称之为:写库: 其它都是从库,负责读取数据 ...
- vue实战教程
转载自 https://www.cnblogs.com/sunsets/p/7760454.html
- leetcode题目234.回文链表(快慢指针+辅助空间-简单)
题目描述: 请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶: 你能否用 O( ...
- JS基础_数组的遍历
遍历:将数组中所有的元素都取出来 1.for循环 var arr = ["1","2","3"]; for(let i=0;i<arr ...
- Arcengine获得arcgis安装的版本
ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Version //gsioracle MessageBox.Show(ESRI.ArcGIS.RuntimeMan ...
- Django知识
复习下django的知识. 1,安装: #pip install django 2.安装完毕后,在当前目录创建工程: #django-admin startproject mysite 执行上方的命令 ...
- typescript简单的应用
简单来说typescript就是新增一下方法,以及增加类型判断 一.普通的类型判断 1.布尔类型(boolean) let isDone: boolean = false let createdByB ...