题目: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. 百度地图API使用

    1.引用js脚本 <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&am ...

  2. 在云服务器搭建WordPress博客(三)安装WordPress

    WordPress的安装在Windows环境下非常简单. 安装前的准备 1.下载最新版的 WordPress,解压后,将WordPress文件夹里面的所有文件,上传到你的主机空间域名所绑定的根目录. ...

  3. 【HDOJ】【4336】Card Collector

    概率DP/数学期望/状压DP/容斥原理 kuangbin总结中的第14题 好神奇的做法……题解看kuangbin的代码好了…… //HDOJ 4336 #include<cstdio> # ...

  4. PHP之SQL防注入代码(360提供)

    <?php class sqlsafe { private $getfilter = "'|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\ ...

  5. Java学习第七篇:与运行环境交互

    目录 一.与用户互动 1.main方法形参 2.使用Scanner类获取输入 3.使用BufferedReader类获取输入 二.常用类 1.System类和Runtime类 2.String, St ...

  6. 想知道吗?CTO 比普通程序员强在哪?

    互联网的蓬勃发展,让无数的程序员身价水涨船高,都变成了「香饽饽」,更有了不少「创业」,「当上 CTO,迎娶白富美的传说」.都说不想当元帅的士兵不是好士兵,我觉得这件事见仁见智,但提升自己的价值,让自己 ...

  7. POJ 1060 Modular multiplication of polynomials(多项式的加减乘除,除法转化成减法来求)

    题意:给出f(x),g(x),h(x)的 (最高次幂+1)的值,以及它们的各项系数,求f(x)*g(x)/h(x)的余数. 这里多项式的系数只有1或0,因为题目要求:这里多项式的加减法是将系数相加/减 ...

  8. 【转】前端图片该保存为什么格式?png or jpg?

    疑虑: 图片存储为web格式,该用什么格式保存呢?png?jpg?压缩比例该为多大?css spript的优劣?有时候我们可能会因为一张格式不正确的图片而导致设计品质的下降以及页面性能的降低.了解图片 ...

  9. 一天,python搞个分析NGINX日志的脚本

    准备给ZABBIX用的. 统计接口访问字次,平均响应时间,4XX,5XX次数 以后可以再改进.. #!/usr/bin/env python # coding: utf-8 ############# ...

  10. Test Markdown Editor

    Last night, I just saw a cute blogger's homepage. Then I want to write something. But anyway, I use ...