[USACO07JAN]Protecting the Flowers S
题意:有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相关推荐
- [BZOJ] 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 827 S ...
- USACO 保护花朵 Protecting the Flowers, 2007 Jan
Description 约翰留下了 N 只奶牛呆在家里,自顾自地去干活了,这是非常失策的.他还在的时候,奶牛像 往常一样悠闲地在牧场里吃草.可是当他回来的时候,他看到了一幕惨剧:他的奶牛跑进了他的花园 ...
- POJ 3262 Protecting the Flowers 贪心(性价比)
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7812 Accepted: ...
- POJ3262 Protecting the Flowers【贪心】
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8663 Accepted: ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心排序)
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 824 S ...
- [USACO 2007 Jan S]Protecting the Flowers
题目: [USACO 2007 Jan S]Protecting the Flowers ,哈哈,我们今天来看一道简单的贪心算法题嘛,这是选自USACO上的一道题,好了,我们一起来看看题意吧: 题目描 ...
- 牛客网 【每日一题】5月28日题目精讲 Protecting the Flowers
链接: 文章目录 题目描述 题意: 题解: 代码: 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目 ...
- 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 ...
- POJ_3262 Protecting the Flowers 【贪心】
一.题面 POJ3262 二.分析 这题要往贪心上面想应该还是很容易的,但问题是要证明为什么比值关系就能满足. 可以选择几个去分析,入1-6 与 2-15 和 1-6 与2-5 和 1-6 与 2 ...
最新文章
- 高逼格UILabel的闪烁动画效果
- php model类,PHP培训之PHP Model类
- java.security.InvalidKeyException: Illegal key size异常解决
- [Android]ListView控件之Adapter性能优化
- 剑指offer:在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。
- Spring MVC-集成(Integration)-集成LOG4J示例(转载实践)
- 微软公司将在英国开设三个数据中心
- I2C总线学习—查缺补漏—对数据有效性的思考
- Udp---模拟实现客户端与服务器通信
- 广州牵引力教育详细分析学习Java能从事前端开发吗?
- java 命令设计模式_Java设计模式之命令设计模式
- webRTC之gtest安装使用(十五)
- Java流(Stream)、文件(File)相关功能 ——菜鸟教程
- 计算机处于离线状态是什么原因,电脑Cortana语音助手显示处于离线状态怎么办?...
- Linux下制作动图的软件,GIF制作教程 | 如何制作高清动图_什么值得买
- 2009福布斯中国上市公司最佳CEO榜
- 关于“TCP segment of a reassembled PDU”
- Color类 设置字体颜色、背景颜色
- 推荐3个搜索资源的网站,保存起来,用的时候方便找哦
- Linux详细到爆炸的一篇文章