[bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心
Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan
题目大意:n头牛,每头牛有两个参数t和atk。表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵花。求一个弄走牛的顺序,使得这些牛破坏最少的花。
注释:$1\le n \le 10^5$。
想法:贪心。
两头牛i和j。
只考虑这两头牛的位置。
如果i在j前面,拉走i的时候j会造成$2t_i*atk_j$朵花。反之同理。
比较两者谁大就放在前面。
在cmp中这样写就行了。
最后,附上丑陋的代码... ...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100010
using namespace std;
typedef long long ll;
struct Node
{
ll t,d;
}a[N];
ll aft[N];
inline bool cmp(const Node &a,const Node &b)
{
return a.d*b.t>b.d*a.t;
}
int main()
{
int n; cin >> n ;
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a[i].t,&a[i].d);
a[i].t*=2;
}
sort(a+1,a+n+1,cmp);
for(int i=n;i>=1;i--)
{
aft[i]=aft[i+1]+a[i].d;
}
// for(int i=1;i<=n;i++) printf("Fuck %d\n",a[i].d);
ll ans=0;
for(int i=1;i<=n-1;i++)
{
ans+=a[i].t*aft[i+1];
}
printf("%lld\n",ans);
return 0;
}
小结:贪心真tm吓人... ...
[bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心的更多相关文章
- BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 448 So ...
- [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 885 So ...
- 【BZOJ】1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1634 贪心.. 我们发现,两个相邻的牛(a和b)哪个先走对其它的牛无影响,但是可以通过 a的破坏花× ...
- BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花:贪心【局部分析法】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正 ...
- bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】
因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdi ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花( 贪心 )
考虑相邻的两头奶牛 a , b , 我们发现它们顺序交换并不会影响到其他的 , 所以我们可以直接按照这个进行排序 ------------------------------------------- ...
- 1634: [Usaco2007 Jan]Protecting the Flowers 护花
1634: [Usaco2007 Jan]Protecting the Flowers 护花 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 493 So ...
- 【bzoj1634】[Usaco2007 Jan]Protecting the Flowers 护花 贪心
题目描述 Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the grass, a ...
- BZOJ 1634: [Usaco2007 Jan]Protecting the Flowers 护花
Description Farmer John went to cut some wood and left N (2 <= N <= 100,000) cows eating the g ...
随机推荐
- 解决 EF where<T>(func) 查询的一个性能问题
前两年帮朋友 做了个网吧管理软件,采用动软的三层架构 sql语句生成的.最近因功能变更 要改动,而我这段正在做asp.net mvc +ef+autofac的一个电商网站.索性 就把原来的底层全重新了 ...
- js 二叉搜索树
二叉搜索树:顾名思义,树上每个节点最多只有二根分叉:而且左分叉节点的值 < 右分叉节点的值 . 特点:插入节点.找最大/最小节点.节点值排序 非常方便 1 2 3 4 5 6 7 8 9 10 ...
- [Swift通天遁地]五、高级扩展-(14)扩展String快速计算字符串中的各种数学表达式
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 《Typecript 入门教程》 2、访问控制符:public、private、protected、readonly
声明类的属性和方法时可以设置使用访问控制符,访问控制符设置类的属性和方法能不能在类的外部被访问 1. 默认为 public,使用public定义的属性和方法在类的内部和外部都可以访问 2. priva ...
- HTML--form表单中的label标签
小伙伴们,你们在前面学习表单各种控件的时候,有没有发现一个标签--label,这一小节就来揭晓它的作用. label标签不会向用户呈现任何特殊效果,它的作用是为鼠标用户改进了可用性.如果你在 labe ...
- 【洛谷2982】[Usaco2010 Feb]慢下来Slowdown(dfs序+线段树)
题目: 洛谷2982 分析: 这道题最重要的是想明白一点:牛\(i\)走到以后只对\(P_i\)的子树产生影响 知道这个以后,就可以想到在线维护每个牧场已经被"影响"了多少次(也就 ...
- android 蓝牙 通信 bluetooth
此例子基于 android demo Android的蓝牙开发,虽然不多用,但有时还是会用到, Android对于蓝牙开发从2.0版本的sdk才开始支持,而且模拟器不支持,测试需要两部手机: ...
- [转]Linux中set,env和export这三个命令的区别
转自:http://www.2cto.com/os/201306/223758.html Linux中set,env和export这三个命令的区别 set命令显示当前shell的变量,包括当前用户 ...
- Spring Cloud (12) 服务网关-基础
通过前几篇介绍,已经可以构建一个简单的微服务架构了,如下图: 通过eureka实现服务注册中心以及服务注册发现,通过ribbon或feign实现服务的消费以及负载均衡,通过spring cloud c ...
- PHP第二阶段学习 一、php的基本语法
php的基本语法 输出语句:a. echo输出:可以输出多个字符串,逗号隔开 b. print输出:只能输出一个字符串,返回true或false c. print_r():可以把字符串和数字简单 ...