1634: [Usaco2007 Jan]Protecting the Flowers 护花
来源:互联网 发布:好用的急救面膜知乎 编辑:程序博客网 时间:2024/05/16 14:01
题目链接
题目大意:把n只奶牛送回牛棚,运送一头奶牛需要t[i]的时间,在运送的时候其他奶牛每分钟吃d[i]朵花(已经或正在被送回去的不吃),安排顺序,使得被吃的花尽量少
题解:调整法应用
对于相邻的x,y
x在y前面 吃的花的数量是d[y]*2*t[x],
y在x前面 吃的花的数量是d[x]*2*t[y],
若x在y前面更优(吃的花数量少),需满足d[y]*t[x]
我的收获:套路+1
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define ll long longint n;ll s,t;struct cow{ int w,v;}c[100005];bool cmp(cow a,cow b){ return a.w*b.v<b.w*a.v;}void init(){ cin>>n; for(int i=1;i<=n;i++) scanf("%d%d",&c[i].w,&c[i].v); sort(c+1,c+1+n,cmp);}int main(){ init(); for(int i=1;i<=n;i++) { s+=c[i].v*t; t+=c[i].w*2; } printf("%lld\n",s); return 0;}
阅读全文
0 0
- 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 护花
- 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 护花(隐藏题)
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
- 【USACO】2007 Jan Protecting the Flowers 保护花朵
- Protecting the Flowers(3262)
- POJ3262-Protecting the Flowers
- [Usaco07Jan] Protecting the Flowers
- [POJ3262]Protecting the Flowers
- POJ Protecting the Flowers
- 简单LinuxC程序关于进制转换(递归函数)
- Java应用基础进阶篇第二章编程题
- 迭代器与生成器
- webpack 打包简介
- 遍历链表
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
- Select服务器代码实现
- css_day01_font(设置字体的样式)
- @Autowired注入空指针
- data-packed volume container
- 半同步/半异步进程池实现
- 快速排序
- 大话工作流:什么是工作流(上)
- Python字典(dict)简介