BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 448 Solved: 276
[Submit][Status]
Description
Farmer John went to cut some wood and left N
(2 <= N <= 100,000) cows eating the grass, as usual. When he returned, he
found to his horror that the cows were in his garden eating his beautiful
flowers. Wanting to minimize the subsequent damage, FJ decided to take immediate
action and transport the cows back to their barn. Each cow i is at a location
that is Ti minutes (1 <= Ti <= 2,000,000) away from the barn. Furthermore,
while waiting for transport, she destroys Di (1 <= Di <= 100) flowers per
minute. No matter how hard he tries,FJ can only transport one cow at a time back
to the barn. Moving cow i to the barn requires 2*Ti minutes (Ti to get there and
Ti to return). Write a program to determine the order in which FJ should pick up
the cows so that the total number of flowers destroyed is minimized.
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
第1行输入N,之后N行每行输入两个整数Ti和Di.
Output
* Line 1: A single integer that is the
minimum number of destroyed flowers
一个整数,表示最小数量的花朵被吞食.
Sample Input
3 1
2 5
2 3
3 2
4
1
1 6
Sample Output
HINT
约翰用6,2,3,4,1,5的顺序来运送他的奶牛.
Source
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
struct rec{int x,y;}a[maxn];
int n;
inline bool cmp(rec a,rec b)
{
return a.x*b.y<a.y*b.x;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
ll sum=;
for(int i=;i<=n;i++)a[i].x=read(),a[i].y=read(),sum+=a[i].y;
sort(a+,a+n+,cmp);
ll ans=;
for(int i=;i<=n;i++)
{
sum-=a[i].y;
ans+=sum**a[i].x;
}
printf("%lld\n",ans);
return ;
}
BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花的更多相关文章
- [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朵 ...
- 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 护花 贪心
题目描述 Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the grass, a ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花
Description Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the g ...
- 【BZOJ】1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1634 贪心.. 我们发现,两个相邻的牛(a和b)哪个先走对其它的牛无影响,但是可以通过 a的破坏花× ...
- BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花:贪心【局部分析法】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正 ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】
因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdi ...
随机推荐
- Disposable microfluidic devices: fabrication, function, and application Gina S. Fiorini and Daniel T
Disposable microfluidic devices: fabrication, function, and application Gina S. Fiorini and Daniel T ...
- DELL R720服务器安装Windows Server 2008 R2 操作系统图文详解
DELL R720服务器安装Windows Server 2008 R2 操作系统图文详解 说明:此文章中部分图片为网络搜集,所以不一定为DELL R720服务器安装界面,但可保证界面内容接近DELL ...
- 窗口 对话框 Pop Dialog 示例
两者的区别 PopupWindow和AlertDialog最大的区别: AlertDialog是非阻塞线程的,AlertDialog弹出的时候,后台可以做其他事情(也即弹出对话框后程序会继续向下执行) ...
- Oracle 11g详细安装配置教程
最近开始学习Oracle数据库了,根据我的理解Oracle数据库是一种强大.复杂.高性能的数据库,而且价格不菲,使用都是中大型企业,土豪专用.学习一种数据库的入门工作就是先安装这种数据库,鉴于大批道友 ...
- ASP.NET页面周期
上图为ASP.NET页面生命周期图. 以下详细讲解一下ASP.NET的页面生命周期. 请求页 请求页发生在页生命周期之前.用户请求时,ASP.NET将确定是否需要分析和编译页面,或者是否可以在不运 ...
- sql Server 常用存储过程的优化
优化存储过程有很多种方法,下面介绍最常用的7种. 1.使用SET NOCOUNT ON选项 我们使用SELECT语句时,除了返回对应的结果集外,还会返回相应的影响行数.使用SET NOCOUNT ON ...
- Mysql数据数据[字节、长度、数据范围]一览表
1.mysql有哪些数据类型: 主要包括以下五大类: 整数类型:BIT.BOOL.TINY INT.SMALL INT.MEDIUM INT. INT. BIG INT 浮点数类型:FLOAT.DOU ...
- javascript 更改控件的class.
指定 className即可, 如通过id,可这样更改: document.getElementById("myDIV").className = "calssName& ...
- swift 闭包 由浅入深 优化
//: Playground - noun: a place where people can play import UIKit ////////////////////////////////// ...
- JAVA-3-水仙花
public static void main(String[] args) { // TODO 自动生成的方法存根 int i = 100; while (i < 1000) { int a, ...