USACO2007 Protecting the Flowers /// 比值 前缀和 oj21161
题目大意:
有N (2 ≤ N ≤ 100,000) 头牛偷吃花
将牛赶回牛棚需Ti minutes (1 ≤ Ti ≤ 2,000,000)
每头牛每分钟能吃Di (1 ≤ Di ≤ 100) 朵花
则赶牛的来回需2*Ti minutes (Ti to get there and Ti to return)
* Line 1: A single integer N
* Lines 2..N+1: Each line contains two space-separated integers, Ti and Di, that describe a single cow's characteristics
* Line 1: A single integer that is the minimum number of destroyed flowers
6
3 1
2 5
2 3
3 2
4 1
1 6
86
一开始用DFS 结果TLE
#include <bits/stdc++.h>
using namespace std;
long long n,ans,sum;
struct cow
{
double t,f,s;
}a[];
bool cmp(struct cow a,struct cow b)
{
return a.s>b.s;
}
int main()
{
scanf("%lld",&n);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&a[i].t,&a[i].f);
a[i].s=a[i].f/a[i].t; ///s为每分钟吃花的数量与赶牛时间的比值
选取耗时少且吃花多的牛能最大限度地减少损失 则应先赶s更大的牛
sum+=a[i].f; ///利用前缀和 省略每次重新循环计量的浪费
}
sort(a+,a++n,cmp);
for(int i=;i<=n;i++)
{
sum-=a[i].f;
ans+=a[i].t*sum*;
}
printf("%lld\n",ans); return ;
}
USACO2007 Protecting the Flowers /// 比值 前缀和 oj21161的更多相关文章
- 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][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
- [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...
- 洛谷——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: ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers
P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...
随机推荐
- JAVA StringUtils 坑汇总
1 StringUtils.split() VS String.split(); public static void main(String args[]){ String r ...
- 洛谷 P4173 残缺的字符串 (FFT)
题目链接:P4173 残缺的字符串 题意 给定长度为 \(m\) 的模式串和长度为 \(n\) 的目标串,两个串都带有通配符,求所有匹配的位置. 思路 FFT 带有通配符的字符串匹配问题. 设模式串为 ...
- 什么是CI/CD?
CI, CD AND CD 当我们在谈论现代的软件编译和发布流程的时候,经常会听到CI 和CD这样的缩写短语.CI很容易理解,就是持续集成.但是CD既可以指代码持续交付,也可理解为代码持续部署.CI和 ...
- MS Sql添加描述信息 及其他信息
--查询某个表的描述 SELECT * FROM fn_listextendedproperty (NULL, 'user', 'dbo', 'table', '(表名)',NULL, NULL) - ...
- OA系统 权限管理的设计流程
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/u013630349/article/det ...
- springMvc框架之Restful风格
method: @Controller @RequestMapping("/test") public String MyController{ @RequestMapping(& ...
- Spring 在Web中的应用
Spring 在Web中的应用 在web项目开发中,不会直接实例化ApplicationContext对象,如果想用到ApplicationContext,一般的步骤: 配置一个监听器ContextL ...
- Hadoop–TaskTracker 相关
TaskTracker 是Hadoop集群中运行于各个节点上的服务.他是JobTracker和Task之间的"通信桥梁".一方面它从JobTracker端接受并执行各种命令:比如运 ...
- 爬虫那些事儿--Http返回码
由于爬虫的抓取也是使用http协议交互.因此需要了解Http的各种返回码所代表的意义,才能判断爬虫的执行结果. 返回码如下: 100 Continue 初始的请求已经接受,客户应当继续发送请求的其余部 ...
- C# Func和匿名方法 简单使用
今天敲代码遇见一个问题,解决中用到了C#的Func和匿名方法,发现挺好用的 定义一个这样的方法可以避免重复写try catch 这里用到了Func<int,string> ,它其实就是一个 ...