[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 ...
随机推荐
- 2.android
ImageButton action_btn = (ImageButton) findViewById(R.id.action_btn);action_btn.setOnClickListener(n ...
- Linux 下文本查找技巧你掌握了吗?
前言 之前介绍过很多linux下查找相关的命令,例如<Linux中的文件查找技巧>,<find命令高级用法>,<如何查看linux中文件打开情况-lsof命令>等等 ...
- Win7 + VS2015 + Python3.6编译
0. 下载安装hg. http://bitbucket.org/tortoisehg/files/downloads/tortoisehg-4.0.1-x64.msi 1. 下载Python3.6源代 ...
- 看无可看 分治FFT+特征值方程
题面: 看无可看(see.pas/cpp/c) 题目描述 “What’s left to see when our eyes won’t open?” “若彼此瞑目在即,是否终亦看无可看?” ---- ...
- IMP-00058 ORA-12638:身份证明检索失败
需要将oracle的tns关掉 1.打开 oracle 的Net Manage 地址:开始 -> 程序 -> Oracle -> Configuration and Migratio ...
- Web程序安全机制
ASP.NET提供了一个多层的安全模型,这个模型能够非常容易的保护Web应用程序. 安全策略没有必要非常复杂,但是需要应用安全策略的地方却是非常广泛的.程序员需要保证自己的应用程序不能被骗取,而把私有 ...
- synchronized关键字详解(一)
synchronized官方定义: 同步方法支持一种简单的策略防止线程干扰和内存一致性错误,如果一个对象对多个线程可见,则对该对象变量的所有读取或写入都是通过同步方法完成的(这一个synchroniz ...
- JS高级——沙箱
基本概念 1.沙箱:与外界隔绝的一个环境,外界无法修改该环境内任何信息,沙箱内的东西单独属于一个世界 2.苹果手的app使用的就是沙箱模式去运行,隔离app的空间,每个app独立运行 js沙箱基本模式 ...
- 从CSDN转到cnblogs了
之前一直用的CSDN的博客,网站卡慢经常出问题,发布文章要审核,连修改几个标点符号也要审核,这些我都忍了,毕竟之前发的文章舍不得弃掉. 现在竟然无故封禁我的博客?请问我写的都是技术文章,有哪点违反规定 ...
- UpdateData
UpdateData 类似于C语言的scanf printf函数 管理控件与关联变量之间的数据更新. updatedata(true)把界面输入的数值更新到关联变量中,updatedata(false ...