题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3850

题解:类似于国王游戏,推一下相邻两个元素交换的条件然后排个序就可以了。

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 200000+5

 #define maxm 200000+5

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)

 #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)

 #define mod 1000000007

 using namespace std;

 inline int read()

 {

     int x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }
struct rec{int x,y;}a[maxn];
int n;
inline bool cmp(rec a,rec b){return a.x*b.y<b.x*a.y;} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); n=read();
for1(i,n)a[i].x=read();
for1(i,n)a[i].y=read();
sort(a+,a+n+,cmp);
ll ans=,sum=;
for1(i,n)
{
sum+=a[i].x;
ans+=sum*(ll)a[i].y;
}
cout<<ans<<endl; return ; }

BZOJ3850: ZCC Loves Codefires的更多相关文章

  1. 【贪心】bzoj3850 ZCC Loves Codefires

    类似某noip国王游戏. 考虑交换两个题目的顺序,仅会对这两个题目的贡献造成影响. 于是sort,比较时计算两个题目对答案的贡献,较小的放在前面. #include<cstdio> #in ...

  2. 2014---多校训练2(ZCC Loves Codefires)

    ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. HDU-4882 ZCC Loves Codefires

    http://acm.hdu.edu.cn/showproblem.php?pid=4882 ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Ot ...

  4. HDU 4882 ZCC Loves Codefires (贪心)

    ZCC Loves Codefires 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/B Description Though ...

  5. HDU 4882 ZCC Loves Codefires(贪心)

     ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  6. hdu 4882 ZCC Loves Codefires(数学题+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...

  7. 2014 (多校)1011 ZCC Loves Codefires

    自从做了多校,整个人都不好了,老是被高中生就算了,题老是都不懂=-=原谅我是个菜鸟,原谅我智力不行.唯一的水题. Problem Description Though ZCC has many Fan ...

  8. BZOJ 3850: ZCC Loves Codefires【贪心】

    Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, called "Memset137". It wa ...

  9. 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...

随机推荐

  1. MVC3 ModelBinder

    1.Model Binder从哪些地方获取数据(找到数据后会停止继续寻找) MVC 框架内置默认的 Model Binder 是 DefaultModelBinder 类.当 Action Invok ...

  2. 解Linux进程间通信(IPC)方式

    http://blog.csdn.net/liuhongxiangm/article/details/7928790 linux下的进程通信手段基本上是从Unix平台上的进程通信手段继承而来的.而对U ...

  3. jquerymobile局部渲染的各种刷新

    在JQueryMobile页面在第一次初始化进行一次整体渲染,动态生成的需要局部渲染. 在jquerymobile实现listview局部渲染的方法: function queryPublishOrd ...

  4. SQLite 学习流水账笔记

    1.SQLite随机取n行数据,可加自己的条件 SELECT * FROM TableName WHERE key ? ORDER BY RANDOM() LIMIT ,Num; 2.sql语句中查询 ...

  5. NGUI Tutorial 3

    一. Create a Button 一.(Menu)NGUI -> Create -> Sprite 二.attach box colider to the Sprite , then ...

  6. nginx去掉单个目录和多个目录PHP执行权限方法

    我们经常希望某些目录不能执行php代码,如果是nginx的话,我们怎么设置Nginx对于某些目录禁止执行PHP权限呢.以前不知道,其实nginx去掉单个目录和多个目录PHP执行权限方法也很简单. 首先 ...

  7. python正则表达式——re模块

    http://blog.csdn.net/zm2714/article/details/8016323 re模块 开始使用re Python通过re模块提供对正则表达式的支持.使用re的一般步骤是先将 ...

  8. IOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途

    iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...

  9. **json_encode:让Json更懂中文(JSON_UNESCAPED_UNICODE)

    我们知道, 用PHP的json_encode来处理中文的时候, 中文都会被编码, 变成不可读的, 类似”\u***”的格式, 还会在一定程度上增加传输的数据量. 代码如下: <?php echo ...

  10. ASP .net(照片列表详细功能演示)

    大家好,今天我们需要讲解的内容就是把上篇文章当中提到的照片列表的很多功能细化去做. 那么之间我们两篇文章的目的就是要让大家深刻体会get,post的使用场景极其作用.像一般处理程序的使用,隐藏域的使用 ...