题意:有n只奶牛正在吃花,农场主要把他们全都抓回去,给出每个奶牛得吃花速度和抓回去得时间(这里时间要乘2,来回),问约翰最少损失多少朵花。
题解:贪心
这题得贪心还是比较明显得,主要是通过分析前后两个整体来进行交换得,我们要考虑先牵哪一头奶牛才能时吃掉的花朵最小,我们可以讨论牛x和牛y
先抓x:2×x.t×y.d
先抓y:2×y.t×x.d

所以我们可以发现优劣取决于x.t×y.d与x.d×y.t两者乘积得大小,如果前者小那就先抓x,后者小那就先抓y,所以可以按照这个标准进行排序。

#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
const int maxn = 1e5+10;
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
ll cnt=0;
struct wazxy{int dis,w;
}a[maxn];
struct rule{bool operator ()(const wazxy & a,const wazxy & b){return a.dis*b.w<b.dis*a.w;}
};
int main()
{int n;cin>>n;for(int i=0;i<n;i++){scanf("%d%d",&a[i].dis,&a[i].w);cnt+=a[i].w;}sort(a,a+n,rule());ll ans=0,rest=0;//cout<<a[0].dis<<endl;for(int i=0;i<n;i++){res***s+=a[i].dis*2*(cnt-rest);//cout<<ans<<endl;}cout<<ans<<endl;return 0;
}

[USACO07JAN]Protecting the Flowers S相关推荐

  1. [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 827  S ...

  2. USACO 保护花朵 Protecting the Flowers, 2007 Jan

    Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...

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

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

  4. POJ3262 Protecting the Flowers【贪心】

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

  5. bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)

    1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 824  S ...

  6. [USACO 2007 Jan S]Protecting the Flowers

    题目: [USACO 2007 Jan S]Protecting the Flowers ,哈哈,我们今天来看一道简单的贪心算法题嘛,这是选自USACO上的一道题,好了,我们一起来看看题意吧: 题目描 ...

  7. 牛客网 【每日一题】5月28日题目精讲 Protecting the Flowers

    链接: 文章目录 题目描述 题意: 题解: 代码: 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目 ...

  8. Protecting the Flowers(POJ-3262)

    Problem Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the g ...

  9. POJ_3262 Protecting the Flowers 【贪心】

    一.题面 POJ3262 二.分析 这题要往贪心上面想应该还是很容易的,但问题是要证明为什么比值关系就能满足. 可以选择几个去分析,入1-6  与 2-15  和 1-6 与2-5 和 1-6 与 2 ...

最新文章

  1. 高逼格UILabel的闪烁动画效果
  2. php model类,PHP培训之PHP Model类
  3. java.security.InvalidKeyException: Illegal key size异常解决
  4. [Android]ListView控件之Adapter性能优化
  5. 剑指offer:在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。
  6. Spring MVC-集成(Integration)-集成LOG4J示例(转载实践)
  7. 微软公司将在英国开设三个数据中心
  8. I2C总线学习—查缺补漏—对数据有效性的思考
  9. Udp---模拟实现客户端与服务器通信
  10. 广州牵引力教育详细分析学习Java能从事前端开发吗?
  11. java 命令设计模式_Java设计模式之命令设计模式
  12. webRTC之gtest安装使用(十五)
  13. Java流(Stream)、文件(File)相关功能 ——菜鸟教程
  14. 计算机处于离线状态是什么原因,电脑Cortana语音助手显示处于离线状态怎么办?...
  15. Linux下制作动图的软件,GIF制作教程 | 如何制作高清动图_什么值得买
  16. 2009福布斯中国上市公司最佳CEO榜
  17. 关于“TCP segment of a reassembled PDU”
  18. Color类 设置字体颜色、背景颜色
  19. 推荐3个搜索资源的网站,保存起来,用的时候方便找哦
  20. Linux详细到爆炸的一篇文章

热门文章

  1. fastText实现文本分类
  2. 文件上传与下载【目前仅仅实现了上传功能】
  3. 迁移学习:领域自适应的理论分析
  4. [Tips]:SQL server 2005 Create Assembly Failed
  5. nginx参数优化杂记
  6. 《windows核心编程系列》十八谈谈windows钩子
  7. VisualStudio:WEB 性能测试和负载测试 入门
  8. Hermite插值是牛顿插值的极限情形
  9. jQuery如何得到tagName?
  10. h.264的NAL和VCL