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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- php 四种基础的算法 ---- 冒泡排序法
1. 冒泡排序法 * 思路分析:法如其名,就是像冒泡一样,每次从数组当中 冒一个最大的数出来. * 比如:2,4,1 // 第一次 冒出的泡是4 * ...
- JS-DOM元素灵活查找
用className选择元素 封装成函数 <title>无标题文档</title> <script> /* window.onload=function () { ...
- spark中groupByKey与reducByKey
[译]避免使用GroupByKey Scala Spark 技术 by:leotse 原文:Avoid GroupByKey 译文 让我们来看两个wordcount的例子,一个使用了reduceB ...
- Talking about Health
George: Doctor, what is the best way to stay healthy? Dictor: Having a good diet is probably the mos ...
- 英文SEO外部链接资源收集之常用的footprints
inurl:/privacy-policy "Using Article Directory plugin"inurl:/terms "Using Article D ...
- webpy
url处理 对于一个站点来说,URL 的组织是最重要的一个部分,因为这是用户看得到的部分,而且直接影响到站点是如何工作的,在著名的站点如:del.icio.us ,其URLs 甚至是网页界面的一部分. ...
- STL笔记之【map之总概】
1.map和multimap内部数据结构: 红黑树(平衡二叉树的一种)2.在往map和multimap中插入元素时,会自动进行排序3.map和multimap的所有元素的key都被视为常数,其元素的实 ...
- Eclipse中Ctrl+Alt+Down和Ctrl+Alt+Up不起作用
不起作用是因为跟因特尔的快捷键冲突. 1.在桌面上右键,选择“图形属性......” 2.选择“选项和支持” 3.更改快捷键. 注意:单纯禁用英特尔的快捷键可能不起作用.
- redmine配置邮件
作为一个项目管理平台,必须能够通知项目成员有关项目和任务的各种状态变化.这也是一种典型的观察者模式.开发人员可以跟踪某个任务,当任务状态.备注.文档.优先级等变化时开发人员就可以得到通知. 对于新配置 ...
- 转 Android开发者指南-Manifest.xml-<supports-screens
<supports-screens> 版本:Android 3.2 语法: <supports-screensandroid:resizeable=["true" ...