POJ 3362 Protecting the Flowers
这题和金华区域赛A题(HDU 4442)是一样的做法。
对两个奶牛进行分析,选择两个奶牛总花费少的方式排序。
bool cmp(const X&a,const X&b)
{
return a.t*b.d<b.t*a.d;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
struct X
{
long long t;
long long d;
} s[maxn];
int n; bool cmp(const X&a,const X&b)
{
return a.t*b.d<b.t*a.d;
} int main()
{
while(~scanf("%d",&n))
{
for(int i=; i<=n; i++) scanf("%lld%lld",&s[i].t,&s[i].d);
sort(s+,s++n,cmp);
long long ans=;
long long sum=*s[].t;
for(int i=; i<=n; i++)
{
ans=ans+s[i].d*sum;
sum=sum+*s[i].t;
}
printf("%lld\n",ans);
}
return ;
}
POJ 3362 Protecting the Flowers的更多相关文章
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- poj 3262 Protecting the Flowers 贪心 牛吃花
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11402 Accepted ...
- poj -3262 Protecting the Flowers (贪心)
http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...
- poj 3262 Protecting the Flowers 贪心
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...
- POJ 3262 Protecting the Flowers 【贪心】
题意:有n个牛在FJ的花园乱吃.所以FJ要赶他们回牛棚.每个牛在被赶走之前每秒吃Di个花朵.赶它回去FJ来回要花的总时间是Ti×2.在被赶走的过程中,被赶走的牛就不能乱吃 思路: 先赶走破坏力大的牛假 ...
- 【POJ - 3262】Protecting the Flowers(贪心)
Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- 修改config.php配置
$data=array( "name"=>"222222", "tel"=>159131, "address" ...
- select初始化默认选项
在写select时由于 在数据库中的得到的值都是字典型的值0,1,2所以在初始化的时候要
- Javascrpit学习之路一——基础知识
1.DOM 文档对象模型 定义:一个与系统平台和编程语言无关的接口,程序和脚本可以通过这个接口动态的访问和修改文档的内容.结构和样式. 2.Javascript 区分大小写.弱类型语言 变量小写:va ...
- AutoTile 自动拼接(四) 学习与实践
今天主要来说下,数据绑定. 之前第一章,我说到 把 资源图 画成格子,你们应该还有印象吧. 那么,当我 知道 格子数据,能否拿到 资源对应的图片呢? 大家先复习一下 第一章,发现很多格子数据 是相同的 ...
- 浅谈C# 多态的魅力(虚方法,抽象,接口实现)
前言:我们都知道面向对象的三大特性:封装,继承,多态.封装和继承对于初学者而言比较好理解,但要理解多态,尤其是深入理解,初学者往往存在有很多困惑,为什么这样就可以?有时候感觉很不可思议,由此,面向对象 ...
- HDU1114--Piggy-Bank(完全背包变形)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- 线关节(Line Joint)
package{ import Box2D.Common.Math.b2Vec2; import Box2D.Dynamics.b2Body; import Box2D.Dynamics.Joints ...
- (二)、Struts第二天
(二).Struts第二天 回顾: 问题: 1. Struts2的Action类是单例还是多例? Filter? Servlet? Listener? 2. 介绍struts2框架引入的相关jar包及 ...
- Eclipse的Java工作集和多工程构建路径
一.Java工作集: Eclipse有一个小功能,就是创建Java Working Set.它的作用是解决Package Explorer窗格中创建很多工程时出现拥挤的麻烦. 在创建(New对话框)时 ...
- 关于Tcpreplay
tcpprep -p -o /root/Desktop/ZS/Tcpreplay/cache_test.cache -i /root/Desktop/ZS/Tcpreplay/9.17.pcap tc ...