这题和金华区域赛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的更多相关文章

  1. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  2. POJ 3262 Protecting the Flowers 贪心(性价比)

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7812   Accepted: ...

  3. poj 3262 Protecting the Flowers 贪心 牛吃花

    Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11402   Accepted ...

  4. poj -3262 Protecting the Flowers (贪心)

    http://poj.org/problem?id=3262 开始一直是理解错题意了!!导致不停wa. 这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛 ...

  5. poj 3262 Protecting the Flowers 贪心

    题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...

  6. POJ 3262 Protecting the Flowers 【贪心】

    题意:有n个牛在FJ的花园乱吃.所以FJ要赶他们回牛棚.每个牛在被赶走之前每秒吃Di个花朵.赶它回去FJ来回要花的总时间是Ti×2.在被赶走的过程中,被赶走的牛就不能乱吃 思路: 先赶走破坏力大的牛假 ...

  7. 【POJ - 3262】Protecting the Flowers(贪心)

    Protecting the Flowers 直接中文 Descriptions FJ去砍树,然后和平时一样留了 N (2 ≤ N ≤ 100,000)头牛吃草.当他回来的时候,他发现奶牛们正在津津有 ...

  8. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 448  So ...

  9. BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )

    考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...

随机推荐

  1. .bash_profile和.bashrc的什么区别

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...

  2. linux命令chown和chmod什么区别

    chown一般用来 更改属主.也就是文件所属用户.chmod功能要比chown要强大.可更改文件所有属性和权限.只有管理员账户才有权限用此命令. chown 是修改文件的所有者(owner),和所属组 ...

  3. C --> OC with RunTime

    前言 本来打算写一篇关于runtime的学习总结,无奈长篇大论不是我的风格,就像写申论一样痛苦,加之网上关于tuntime的文章多如牛毛,应该也够童子们学习的了,今天就随便聊聊我的理解吧. runti ...

  4. postgresql 在linux上的源码安装

    http://my.oschina.net/hippora/blog/375292 下载源码并解压 [root@fnddb ~]# wget https://ftp.postgresql.org/pu ...

  5. GameUnity 2.0 文档(二) 纸片人系统

    本想快速的 把 之前写的类库,一股脑的 给大家 ,但又觉得,如 msdn那样的 文档,并不能给 初学者 所能接受. 因为 大部分人 对 api 还是比较陌生,也不愿意 去研究和组合. 那么 今天我选用 ...

  6. java 实例变量和类变量的区别

    Example4_10.java public class Example4_10 { public static void main(String args[]) { Lader.下底=100; / ...

  7. XML回顾

    xml加强 一.sax解析    1)原理: 读取xml的某个部分,解析一部分(读取一点,解析一点)    2)步骤:         SAXParserFactory factory = SAXPa ...

  8. DFS序的题目列表

    所谓dfs序就是将之前的顺序进行修改,获得一个新的序列,然后再新的序列下进行一系列其他的操作 一般题目给你的都会是一棵树,然后点之间都是无关的,我们首要的任务就是先把这些序列重新排.然后再根据dfs的 ...

  9. filters

    http://www.cloudera.com/content/cloudera/en/documentation/core/latest/topics/admin_hbase_filtering.h ...

  10. ural1037 Memory Management

    Memory Management Time limit: 2.0 secondMemory limit: 64 MB Background Don't you know that at school ...