Description

约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的。他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草。可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园, 正在啃食他精心培育的花朵!约翰要立即采取行动,挨个把它们全部关回牛棚。 约翰牵走第 i 头奶牛需要 T i 分钟,因为要算来回时间,所以他实际需要 2 · T i 分钟。第 i 头奶牛 如果还在花园里逍遥,每分钟会啃食 Di 朵鲜花。但只要约翰抓住了它,开始牵走它的那刻开始,就 没法吃花了。请帮助约翰写一个程序来决定押送奶牛的顺序,使得花朵损失的数量最小。

Input Format

• 第一行:单个整数 N ,1 ≤ N ≤ 100000• 第二行到第 N + 1 行:第 i + 1 行有两个整数 T i 和 Di,2 ≤ T i ≤ 10 6 ; 1 ≤ Di ≤ 100

Output Format

• 单个整数:表示约翰损失的最小花朵数量

Sample Input

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

Sample Output

86

Hint

依次制服第六头,第二头,第三头,第四头, 第一头和第五头

Source

Protecting the Flowers, 2007 Jan
由题目可知对于 Ta Da Tb Db
只对后状态影响 设影响为w;则后状态为∑Di(max(a,b)+1<=i<=n)
若a排b前 w=Ta(∑Di+Db)+Tb*∑Di;
若b排a前 w=Tb(∑Di+Da)+Ta*∑Di;
消元后 发现 我们只要 对 Ta*Db<Tb*Da情况排序
然后模拟即可
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int i,j,k,l,m,n;
long long ans,sum;
struct st{int w,t;}mu[100010];
bool cmp(const st x,const st y)
{
if(x.t*y.w<y.t*x.w)return true;
return false;
}
int main()
{
// freopen("xx.in","r",stdin);
scanf("%d",&n);
for(i=1;i<=n;sum+=mu[i].t*2,++i)
scanf("%d%d",&mu[i].t,&mu[i].w);
sort(mu+1,mu+n+1,cmp);
long long num=sum;
for(i=1;i<=n;++i)
{
ans+=(sum-num)*mu[i].w;
num-=mu[i].t*2;
}
printf("%lld",ans);
}

  

USACO 保护花朵 Protecting the Flowers, 2007 Jan的更多相关文章

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

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

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

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

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

    题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...

  4. Luogu_2878_[USACO07JAN]保护花朵Protecting the Flowers

    题目描述 Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. ...

  5. P2878 [USACO07JAN]保护花朵Protecting the Flowers

    一个类似国王游戏的贪心 话说要是先做了这个题,国王游戏之余懵逼这么久吗? #include<iostream> #include<cstdio> #include<alg ...

  6. USACO Protecting the Flowers

    洛谷 P2878 [USACO07JAN]保护花朵Protecting the Flowers 洛谷传送门 JDOJ 1009: 护花 JDOJ传送门 Description FJ出去砍木材去了,把N ...

  7. NC25043 [USACO 2007 Jan S]Protecting the Flowers

    NC25043 [USACO 2007 Jan S]Protecting the Flowers 题目 题目描述 Farmer John went to cut some wood and left ...

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

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

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

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

随机推荐

  1. C++目录遍历:使用第三方库boost.filesystem等

    1. opencv 目录文件遍历 注释:2014 0814 这个代码是基于java的,Java使用托管代码进行目录管理,C++就不那么跨平台了. 原文链接:http://blog.csdn.net/z ...

  2. sqlserver 分组 group by

    select 名称, COUNT(名称) as 数量之和from 信息group by all 名称

  3. 【转】【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之缓存融合技术和主要后台进程(四)

    原文地址:http://www.cnblogs.com/baiboy/p/orc4.html   阅读目录 目录 Cache Fusion 原理 什么是 Cache Fusion? 什么是高可用 FA ...

  4. bzoj 1189: [HNOI2007]紧急疏散evacuate 分层图最大流_拆点_二分

    Description 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一 块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是 ...

  5. Nginx全局变量

    一.全局变量 $args #请求中的参数值 $query_string #同 $args $arg_NAME #GET请求中NAME的值 $is_args #如果请求中有参数,值为"?&qu ...

  6. Nginx配置udp/tcp代理

    #编译 ./configure --prefix=/servyouapp/nginx --with-stream --with-http_stub_status_module #nginx.conf部 ...

  7. Centos 7.2 安装和卸载 MySQL 5.7

    一.背景 闲暇之余在虚拟机安装了 Centos 7.2 系统,按照 <简单安装MySQL(RPM方式)> 这篇文章安装 MySQL ,发现由于包依赖的问题安装失败,于是索性在官网查询相关文 ...

  8. docker 私有仓库的两种方式

    1.使用官方默认的registry镜像构建本地仓库 这种方式适用于小规模的镜像仓库储存,没有Ui界面 (1)docker pull registry (2)docker run -d -p 5000: ...

  9. Python-基础-day2

    Python环境的安装 安装Python: windows: 1.下载安装包     https://www.python.org/downloads/ 2.安装     默认安装路径:C:\pyth ...

  10. Ubuntu中无法update的解决办法

    我输入 sudo apt-get update 出现错误: /etc/apt$ sudo apt-get update Err http://security.ubuntu.com precise-s ...