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 , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
随机推荐
- struts2中的文件上传,文件下载
文件上传: Servlet中的文件上传回顾 前台页面 1.提交方式post 2.表单类型 multipart/form-data 3.input type=file 表单输入项 后台 apache提交 ...
- Jmeter的优点是什么?除了轻量级,它和LoadRunner有什么本质区别
1.jmeter的架构和loadrunner原理一样,都是通过中间代理,监控和收集并发客户端发出的指令,把他们生成脚本,再发送到应用服务器,再监控服务器反馈结果的一个过程: 2.分布式中间代理功能在j ...
- KNN邻近分类算法
K邻近(k-Nearest Neighbor,KNN)分类算法是最简单的机器学习算法了.它采用测量不同特征值之间的距离方法进行分类.它的思想很简单:计算一个点A与其他所有点之间的距离,取出与该点最近的 ...
- 利用Hierarchy Viewer优化布局
好久没更新博客了,趁着清明来写点什么. 今天来讲下如何使用android中提供的工具优化我们的布局.首先我们写一个最简单的框架布局. <?xml version="1.0" ...
- HDU 2674 N!Again
一开始以为有循环节,输出了前100项发现n>40都是0.因此,水题.... #include<cstdio> ]; ; int main() { a[]=; ; i<=; i+ ...
- java工程开发之图形化界面之(第四课)
本节中,我们将创建一个小应用程序,它使用循环生成其图案.我们将使用if语句和setColor方法.同时我们将介绍drawString方法,并使用它在小应用程序窗口中写出文本. 下面的小应用程序是显示一 ...
- c语言字符串转OC字符串
// 如果把c语言字符串转OC字符串,@(C字符串) char *c = "abc"; NSLog(@"%@", @(c));
- GuideActivity.java引导界面:
这是谷歌官方给我们提供的一个兼容低版本安卓设备的软件包,里面包囊了只有在安卓3.0以上可以使用的api. 而viewpager就是其中之一利用它,我们可以做很多事情,从最简单的导航,到页面菜单等等.那 ...
- HDOJ1312<DFS>
题意: 给一张图,有墙,有路.问某人从起点开始,最多能走多少个格子. 思路: bfs;<水题> #include<iostream> #include<cstring&g ...
- apk文件分析原则
如果在dex生成的jar文件里没有发现关键内容的话,就要注意jar里面的native函数以及loadlibrary操作,从而可以判断出加载了哪些so,调用了什么函数.就不会出现判断不出是不是加载了某s ...