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

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100005;
int n;
long long ans,sum;
struct qwe
{
int v,t;
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return (double)a.v/a.t>=(double)b.v/b.t;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
a[i].t=read()*2,a[i].v=read(),sum+=a[i].v;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
sum-=a[i].v;
ans+=sum*a[i].t;
}
printf("%lld\n",ans);
return 0;
}

bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  9. [bzoj1634][Usaco2007 Jan]Protecting the Flowers 护花_贪心

    Protecting the Flowers 护花 bzoj-1634 Usaco-2007 Jan 题目大意:n头牛,每头牛有两个参数t和atk.表示弄走这头牛需要2*t秒,这头牛每秒会啃食atk朵 ...

随机推荐

  1. 关于zkfc与zkserver频繁断开的问题

    详见http://blog.csdn.net/dslztx/article/details/51596951

  2. JavaEE JDBC RowSet行集

    RowSet行集 @author ixenos 应用背景 1.基于结果集的缺点:在与用户的整个交互过程中,必须始终与数据库保持连接 后果:当用户长时间离开时,数据库连接长时间被占用,而这属于稀缺资源: ...

  3. android开发里跳过的坑——图片文件上传失败

    使用的apache的httpclient的jar包,做的http图片上传,上传时,服务器总返文件格式不对.后来发现,是由于在创建FileBody时,使用了默认的ContentType引起的.所以服务器 ...

  4. 【进击后端】mongodb入门

    环境:ubuntu 重要字:数据库,集合,记录,字段 api地址:https://docs.mongodb.com/manual/reference/method/db.collection.upda ...

  5. springboot技术

      一 我们为什么要用SpringBoot? 1. SpringBoot核心功能 SpringBoot的核心最足要的功能是自动配置,简单说下springBoot,springboot可以替代额xml配 ...

  6. ArcGIS for Android入门程序之DrawTool2.0

    来自:http://blog.csdn.net/arcgis_mobile/article/details/8084763 GISpace博客<ArcGIS for Android入门程序之Dr ...

  7. maven 手动构建项目

    maven 手动构建项目 在空目录下面: D:\test>mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archet ...

  8. 012 router password

    Press RETURN to get started!       Router>en Router#config t Enter configuration commands, one pe ...

  9. 编程算法 - n个骰子的点数(递归) 代码(C)

    n个骰子的点数(递归) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 把n个骰子仍在地上, 全部骰子朝上一面的点数之和为s. 输入n, 打印出 ...

  10. 百度编辑器ueditor给上传的图片加入水印

    百度编辑器本身是没有为上传图片加入水印的功能,想要在上传的时候加入图片水印,也非常easy.以 ueditor 1.2.6 为例.打开php文件夹以下的imageUp.php文件,查找"$i ...