[bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan
题目大意:n头牛,每头牛有两个参数t和atk。表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵花。求一个弄走牛的顺序,使得这些牛破坏最少的花。
注释:$1\le n \le 10^5$。
想法:贪心。
两头牛i和j。
只考虑这两头牛的位置。
如果i在j前面,拉走i的时候j会造成$2t_i*atk_j$朵花。反之同理。
比较两者谁大就放在前面。
在cmp中这样写就行了。
最后,附上丑陋的代码... ...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
using namespace std;
typedef long long ll;
struct Node
{
ll t,d;
}a[N];
ll aft[N];
inline bool cmp(const Node &a,const Node &b)
{
return a.d*b.t>b.d*a.t;
}
int main()
{
int n; cin >> n ;
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a[i].t,&a[i].d);
a[i].t*=2;
}
sort(a+1,a+n+1,cmp);
for(int i=n;i>=1;i--)
{
aft[i]=aft[i+1]+a[i].d;
}
// for(int i=1;i<=n;i++) printf("Fuck %d\n",a[i].d);
ll ans=0;
for(int i=1;i<=n-1;i++)
{
ans+=a[i].t*aft[i+1];
}
printf("%lld\n",ans);
return 0;
}
小结:贪心真tm吓人... ...
[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: 448 So ...
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
- 【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 ...
- 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 ...
随机推荐
- 数据库部署到linux服务器,供本地访问。
1. 将本地的sql文件上传至服务器 scp /Users/fangke/Documents/article.sql root@IP:/usr/local 2. 登陆服务器的mysql 3. 创建数 ...
- C# System.Environment.GetFolderPath的使用 [转]
原文:https://blog.csdn.net/yongyong521/article/details/75105853 获取系统文件目录 string strPath = Environment. ...
- mysql中类型转换
MySQL 的CAST()和CONVERT()函数可用来获取一个类型的值,并产生另一个类型的值 CAST(xxx AS 类型), CONVERT(xxx,类型) 二进制,同带binary前缀的效果 : ...
- 再战primer——decltype 和引用
刷primer看到原文讲到"引用从来都作为其所指对象的同义词出现,只有用在decltype处是一个例外.",我很是好奇. 这个“引用”当然是指引用类型,like this: ; i ...
- Unity学习-碰撞检测(七)
Unity脚本说明 Unity支持语言: C#(主流),JavaScript,Boo 创建脚本: [Assets-Create-C# Script] 学习案例 布置场景: 添加一个Plane,3个Cu ...
- pd_ds 之 hash
http://attack.cf/?post=23 打个广告....
- HTML TabIndex属性
TabIndex作用: tabindex:全局属性.指示其元素是否可以聚焦(获得焦点),以及它是否/在何处参与顺序键盘导航(因通常使用tab键操作,顾因此得名). 当使用tab键在网页控件中进行导航时 ...
- StackOverflowError&OutOfMemoryError区别
在Java虚拟机规范中,针对内存分配规定两种异常状况,即StackOverflowError和OutOfMemoryError. StackOverflowError:当线程请求的内存大小大于所配置的 ...
- JS——隐式全局变量
在函数中,var声明的是局部变量,不带var的是隐式全局变量 <script> function fn() { var a = b = c = 0;//a是局部变量,b.c是全局变量 va ...
- css知识框架