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. eclipse下整合springboot和mybatis

    1.新建maven项目 先新建一个maven项目,勾选上creat a simple project,填写groupid,artifactid 2.建立项目结构 3.添加依赖 <parent&g ...

  2. Java中多个线程交替循环执行

    有些时候面试官经常会问,两个线程怎么交替执行呀,如果是三个线程,又怎么交替执行呀,这种问题一般人还真不一定能回答上来.多线程这块如果理解的不好,学起来是很吃力的,更别说面试了.下面我们就来剖析一下怎么 ...

  3. PKUSC2017 游记 密码:blog密码

    退役之前,写点破事乐呵乐呵 省选滚大粗   报了PKU和THU的SC  果然THU直接审核不通过... 于是就来到了PKU   滚粗狗就又续命几天. Day1 上午考数学 喜闻乐见啥都不会 出来一对题 ...

  4. html表单代码演示

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  5. Spring Cloud (5) 分布式配置中心

    Spring Cloud Config 在分布式系统中,由于服务数量很多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,使用Spring Cloud ...

  6. mysql简单增删改查(CRUD)

    先描述一下查看表中所有记录的语句以便查看所做的操作(以下所有语句建议自己敲,不要复制以免出错): user表,字段有 id, name,age,sex:id为主键,自增,插入时可以写 NULL 或者 ...

  7. enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程

    这里是要把http://www.cnblogs.com/hackfun/p/6260396.html中的enc28j60网卡驱动模块,添加到2.6.22.6内核中,这个模块代码不需要任何修改.只需要在 ...

  8. Java常用开源jar包

    转:http://blog.csdn.net/kevingao/article/details/8125683 activation~与javaMail有关的jar包,使用javaMail时应与mai ...

  9. [Windows Server 2008] 安装网站伪静态

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS伪静 ...

  10. 实验1 C++函数

    一.实验目的: 掌握定义函数的方法.函数实参与形参的对应关系以及“值传递”的方式. 熟悉函数的嵌套调用和递归调用的方法. 熟悉全局变量.局部变量概念和使用方式. 二.实验内容: 运行调试第2章编程示例 ...