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. UWP Ad

    1.对于 UWP 应用:使用 Visual Studio 2015 安装 Microsoft Store Services SDK 2.对于通用 Windows 平台 (UWP) 项目:展开通用 Wi ...

  2. 实验6 Bezier曲线生成

    1.实验目的: 了解曲线的生成原理,掌握几种常见的曲线生成算法,利用VC+OpenGL实现Bezier曲线生成算法. 2.实验内容: (1) 结合示范代码了解曲线生成原理与算法实现,尤其是Bezier ...

  3. CSS读书笔记(3)---清除浮动的几种方法

    浮动元素容易造成页面错位现象.下面说说关于清除浮动的几种方法. 首先.先创建一个浮动导致错位的页面. <!DOCTYPE html> <html lang="en" ...

  4. java 1.8 内存告警问题

    Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=512m; support was removed in 8.0 ...

  5. JDBC连接MySQL数据库(一)——数据库的基本连接

    JDBC的概念在使用之前我们先了解一下JDBC的概念, JDBC的全称是数据库连接(Java Database Connectivity),它是一套用于执行SQL语句时的API,应用程序可以通过这套A ...

  6. websocket 进阶!netty框架实现websocket达到高并发

    引言: 在前面两篇文章中,我们对原生websocket进行了了解,且用demo来简单的讲解了其用法.但是在实际项目中,那样的用法是不可取的,理由是tomcat对高并发的支持不怎么好,特别是tomcat ...

  7. Nginx部署静态资源(及root与alias区别)

    root目录与alias目录的区别Nginx路径location配置中,使用root目录与alias目录的区别 1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是 ...

  8. css3实现滚动手表

    静态html: <!DOCTYPE html><html> <head> <meta charset="utf-8" /> < ...

  9. 批量修改Linux系统密码

    截取主机IP地址最后一位数.匹配一组定义好的自定义密码.使用chpasswd修改主机账户密码 截图主机IP [root@web01 ~]# ip addr 1: lo: <LOOPBACK,UP ...

  10. 2019-03-28 SQL inner left full

    在使用 join 时,on 和 where 条件的区别如下: 1. on 条件是在生成临时表时使用的条件,它不管 on 中的条件是否为真,都会返回左边表中的记录. 2.where 条件是在临时表生成好 ...