bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
来源:互联网 发布:海知智能 编辑:程序博客网 时间:2024/05/16 17:50
1634: [Usaco2007 Jan]Protecting the Flowers 护花
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 824 Solved: 534
[Submit][Status][Discuss]
Description
约翰留下他的N只奶牛上山采木.他离开的时候,她们像往常一样悠闲地在草场里吃草.可是,当他回来的时候,他看到了一幕惨剧:牛们正躲在他的花园里,啃食着他心爱的美丽花朵!为了使接下来花朵的损失最小,约翰赶紧采取行动,把牛们送回牛棚. 牛们从1到N编号.第i只牛所在的位置距离牛棚Ti(1≤Ti《2000000)分钟的路程,而在约翰开始送她回牛棚之前,她每分钟会啃食Di(1≤Di≤100)朵鲜花.无论多么努力,约翰一次只能送一只牛回棚.而运送第第i只牛事实上需要2Ti分钟,因为来回都需要时间. 写一个程序来决定约翰运送奶牛的顺序,使最终被吞食的花朵数量最小.
Input
第1行输入N,之后N行每行输入两个整数Ti和Di.
Output
一个整数,表示最小数量的花朵被吞食.
Sample Input
6
3 1
2 5
2 3
3 2
4 1
1 6
Sample Output
86
假设只有两头牛
送回牛棚的时间为T1、T2,每秒吃w1、w2朵花
显然当T1*w2<T2*w1时先送第一头牛会更优
那么有n条牛时其实只要按Ti*wj<Tj*wi的规则排序就好了
#include<stdio.h>#include<algorithm>using namespace std;#define LL long longtypedef struct Res{int t, d;bool operator < (const Res &b) const{if(t*b.d<d*b.t)return 1;return 0;}}Res;Res s[100005];int main(void){LL ans, time;int n, i;scanf("%d", &n);for(i=1;i<=n;i++)scanf("%d%d", &s[i].t, &s[i].d);sort(s+1, s+n+1);ans = time = 0;for(i=1;i<=n;i++){ans += time*s[i].d;time += s[i].t*2;}printf("%lld\n", ans);return 0;}
阅读全文
1 0
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
- |BZOJ 1634|贪心|[Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ [Usaco2007 Jan]Protecting the Flowers 护花(隐藏题)
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- [BZOJ1634] [Usaco2007 Jan]Protecting the Flowers 护花
- bzoj1634[Usaco2007 Jan]Protecting the Flowers 护花
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
- Protecting the Flowers (贪心)
- Protecting the Flowers(POJ3262)(贪心)
- poj 3262 Protecting the Flowers(贪心)
- poj3262 Protecting the Flowers(贪心)
- POJ 3262 - Protecting the Flowers(贪心)
- POJ 3262 Protecting the Flowers (贪心)
- oracle从入门到放弃
- 视图
- C++STL库 vector map list 使用方法
- 次小生成树 prim和kruskal
- BeautifulSoup库入门级方法
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
- 背包九讲系列2——混合背包、二维费用背包、分组背包
- [JS] JS递归常见问题
- oracle(01): 创建表,主键自增长,注解,视图,序列
- 中缀表达式转后缀表达式(又称逆波兰式)
- Convert Sorted List to Binary Search Tree
- 清除匿名定时器
- CodeForces 136 A.Presents(水~)
- tensorflow1.3.0安装注意