http://poj.org/problem?id=3262

开始一直是理解错题意了!!导致不停wa。

这题是农夫有n头牛在花园里啃花朵,然后农夫要把它们赶回棚子,每次只能赶一头牛,并且给出赶回每头牛需要的时间和牛在花园每分钟吃多少花朵,问你怎么安排让损失最小。

这题单独按time和eat排序都不行,得按它们的比率来排,如果是选择eat/time  则从大到小排,time/eat则从小到大排,但是不会严格证明。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <vector>
  5. #include <cstring>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <set>
  10. #include <functional>
  11. #include <numeric>
  12. #include <sstream>
  13. #include <stack>
  14. #include <map>
  15. #include <queue>
  16.  
  17. #define CL(arr, val) memset(arr, val, sizeof(arr))
  18.  
  19. #define ll long long
  20. #define inf 0x7f7f7f7f
  21. #define lc l,m,rt<<1
  22. #define rc m + 1,r,rt<<1|1
  23. #define pi acos(-1.0)
  24.  
  25. #define L(x) (x) << 1
  26. #define R(x) (x) << 1 | 1
  27. #define MID(l, r) (l + r) >> 1
  28. #define Min(x, y) (x) < (y) ? (x) : (y)
  29. #define Max(x, y) (x) < (y) ? (y) : (x)
  30. #define E(x) (1 << (x))
  31. #define iabs(x) (x) < 0 ? -(x) : (x)
  32. #define OUT(x) printf("%I64d\n", x)
  33. #define lowbit(x) (x)&(-x)
  34. #define Read() freopen("a.txt", "r", stdin)
  35. #define Write() freopen("dout.txt", "w", stdout);
  36. #define N 100005
  37. using namespace std;
  38.  
  39. struct point
  40. {
  41. int x,y;
  42. double d;
  43. bool operator <(const point &a) const
  44. {
  45. return d>a.d;
  46. }
  47. }p[];
  48. int main()
  49. {
  50. //Read();
  51. int n;
  52. ll sum,t;
  53. while(~scanf("%d",&n))
  54. {
  55. sum=t=;
  56. for(int i=;i<n;i++)
  57. {
  58. scanf("%d%d",&p[i].x,&p[i].y);
  59. p[i].d=p[i].y*1.0/p[i].x;
  60. t+=p[i].y; //这样处理 方便计算
  61. }
  62. sort(p,p+n);
  63. //for(int i=0;i<n;i++) printf("%d %d\n",p[i].x,p[i].y);
  64. for(int i=;i<n;i++)
  65. {
  66. t-=p[i].y;
  67. sum+=p[i].x*t*;
  68. }
  69. printf("%lld\n",sum);
  70. }
  71. return ;
  72. }

poj -3262 Protecting the Flowers (贪心)的更多相关文章

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

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

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

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

  3. poj 3262 Protecting the Flowers 贪心

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

  4. poj 3262 Protecting the Flowers

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

  5. POJ 3262 Protecting the Flowers 【贪心】

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

  6. POJ 3362 Protecting the Flowers

    这题和金华区域赛A题(HDU 4442)是一样的做法. 对两个奶牛进行分析,选择两个奶牛总花费少的方式排序. bool cmp(const X&a,const X&b){ return ...

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

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

  8. POJ3262 Protecting the Flowers 【贪心】

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

  9. [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心

    Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...

随机推荐

  1. 在listener或者工具中使用spring容器中的bean实例

    在项目中经常遇见需要在Listener中或者工具中使用Spring容器中的bean实例,由于bean不能在stataic的类中使用. 介绍一种方式: public class SpringTool { ...

  2. bzoj 3171 费用流

    每个格拆成两个点,出点连能到的点的入点,如果是箭头指向 方向费用就是0,要不就是1,源点连所有出点,所有入点连 汇点,然后费用流 /********************************** ...

  3. 剑指offer--面试题20

    题目:从外向里顺时针打印矩阵 做题心得:该题本质上并未考查复杂的数据结构及算法,而是考查了快速找规律的能力!!! 要想作出此题,必须先有绝对清晰的思路,否则越写越乱(因为涉及到很多的循环打印) 自己当 ...

  4. 树分治&树链剖分相关题目讨论

    预备知识 树分治,树链剖分   poj1741 •一棵有n个节点的树,节点之间的边有长度.方方方想知道,有多少个点对距离不超过m 题解 点分治模板题.详见我早上写的http://www.cnblogs ...

  5. 【ASP.Net MVC】在AspNet Mvc使用Ajax

    目录 一.使用System.Web.Mvc.Ajax 1.1 System.Web.Mvc.Ajax.BeginForm 1.2 System.Web.Mvc.Ajax.ActionLink 二.手工 ...

  6. 使用ajax技术无刷新动态调用股票信息

    新浪的财金频道一直感觉做得很好.但由于最近网速慢的缘故,查看股票信息时网页老是打不开.这几天一直在研究ajax,于是用jquery自己做了一个自动读取新浪股票实时数据的页面. <html> ...

  7. js prompt函数使用例子

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  8. FZU2165 v11(带权的重复覆盖)

    题意:有n个boss,m种武器,每种武器选用的时候需要有一定的花费ci,然后这个武器可以消灭掉其中一些BOSS,问你消灭完所有的BOSS,需要的最少花费是多少. 当时比赛的时候,看到这题以为是什么网络 ...

  9. codeforces 439C Devu and Partitioning of the Array(烦死人的多情况的模拟)

    题目 //这是一道有n多情况的烦死人的让我错了n遍的模拟题 #include<iostream> #include<algorithm> #include<stdio.h ...

  10. hdu 4389 X mod f(x) 数位DP

    思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...