题目大意:

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)

Input

* 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

Output

* Line 1: A single integer that is the minimum number of destroyed flowers

Sample Input

6
3 1
2 5
2 3
3 2
4 1
1 6

Sample Output

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的更多相关文章

  1. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 448  So ...

  2. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

  3. 1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 493  So ...

  4. [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 885  So ...

  5. [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心

    Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...

  6. 洛谷——P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 题目描述 Farmer John went to cut some wood and left N (2 ≤ ...

  7. POJ 3262 Protecting the Flowers 贪心(性价比)

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7812   Accepted: ...

  8. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  9. bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...

随机推荐

  1. 关于python语言学习心得

    最近又开始学习代码了,中途停顿了2个月左右,学习贵在坚持. 内心非常渴望学会一门编程语言,对代码目前来说还不是排斥. 也没有什么好的学习方法,只是按照同事说的,买了一本书籍来,边看边练习,先熟悉它的语 ...

  2. Java-Class-@I:org.springframework.web.bind.annotation.PostMapping

    ylbtech-Java-Class-@I:org.springframework.web.bind.annotation.PostMapping 1.返回顶部   2.返回顶部 1. package ...

  3. 【前端控件】JQuery datepicker 日期控件设置

    datepicker控件可通过参数设置进行语言切换,以下可实现,系统所有日期控件默认为中文,在特定页面或者特定条件下可切换成英语!~ HTML: <!DOCTYPE html> <h ...

  4. 假如Kafka集群中一个broker宕机无法恢复,应该如何处理?

    假如Kafka集群中一个broker宕机无法恢复, 应该如何处理? 今天面试时遇到这个问题, 网上资料说添加新的broker, 是不会自动同步旧数据的. 笨办法 环境介绍 三个broker的集群, z ...

  5. 反射与类加载之反射基本概念与Class(一)

    更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从以下几个内容来阐述反射与类加载: [三种获取Class对象的方式] [ ...

  6. python 基本输入输出

  7. Pregel Worker

  8. wc - 输出文件中的字节数、单词数、行数

    SYNOPSIS 总览 wc [选项列表]... [文件名列表]... DESCRIPTION 描述 对每个文件输出行.单词.和字节统计数,如果指定了多于一个文件则还有一个行数的总计.没有指定文件或指 ...

  9. 微信小程序控件

    1   scrollview 窗口view的滑动 <scroll-view scroll-y class='scroll-view-y' bindscrolltoupper="uppe ...

  10. ubuntu查看时间同步服务器的匹配源

    当服务器时间与设定好的同步时间源的时间有差异的时候,一般都需要先查看本机的时间同步服务功能是否在正常的运转,以及同步的时间源是哪里,在这里为大家提供一个检查时间用的命令. ubuntu版本 servi ...