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 护花_贪心的更多相关文章

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

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

  2. [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花 贪心

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

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1634 贪心.. 我们发现,两个相邻的牛(a和b)哪个先走对其它的牛无影响,但是可以通过 a的破坏花× ...

  4. BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花:贪心【局部分析法】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正 ...

  5. bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】

    因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdi ...

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

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

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

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

  8. 【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 ...

  9. 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 ...

随机推荐

  1. ural 1017. Staircases(dp)

    http://acm.timus.ru/problem.aspx?space=1&num=1017 题意:有n块砖,要求按照严格递增的个数摆放成楼梯,求楼梯的摆放种类数. 思路:状态转移方程: ...

  2. keystone身份认证服务

    Keystone介绍 keystone 是OpenStack的组件之一,用于为OpenStack家族中的其它组件成员提供统一的认证服务,包括身份验证.令牌的发放和校验.服务列表.用户权限的定义等等.云 ...

  3. 313 Super Ugly Number 超级丑数

    编写一段程序来寻找第 n 个超级丑数.超级丑数是指其所有质因数都在长度为k的质数列表primes中的正整数.例如,[1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] ...

  4. MVC系列学习(五)-传递数据 与 接收数据

    1.控制器向视图传递数据 a.使用ViewData b.使用ViewBag c.使用Model 方式二: d.使用TempData 2.为什么在控制器中设置了一些属性,在视图中可以接受 3.Actio ...

  5. [ POI 2011 ] Dynamite

    \(\\\) \(Description\) 一棵\(N\)个节点的树,树上有\(M\)个节点是关键点,选出\(K\)个特殊点,使得所有关键点到特殊点的距离中最大的最小,输出最大值最小为多少. \(N ...

  6. Android项目实战_手机安全卫士软件管家

    ###1.应用程序信息的flags 1. int flags = packageInfo.applicationInfo.flags2. 0000 0000 0000 0000 0000 0000 0 ...

  7. zabbix配置邮件报警(第四篇)

    zabbix配置邮件报警(第四篇) 邮件报警可采用本地邮件服务,也可以自定义脚本,这里我采用本地邮件服务报警 添加收件人

  8. Quartz实战

    https://my.oschina.net/yinxiaoling/blog/542336?fromerr=s3ko7u33 Quartz实战 > 一.内存型(1) <bean name ...

  9. (转)Hibernate的优化方案

    http://blog.csdn.net/yerenyuan_pku/article/details/70768603 HQL优化 使用参数绑定  使用绑定参数的原因是让数据库一次解析SQL,对后续的 ...

  10. android Adapter总结

    1.连接视图与数据.数据封装: 2.视图构造与配置: 3.数据更新监听: 4.视图重用机制. * An Adapter object acts as a bridge between an {@lin ...