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

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

代码:

  1. #include<cstdio>
  2.  
  3. #include<cstdlib>
  4.  
  5. #include<cmath>
  6.  
  7. #include<cstring>
  8.  
  9. #include<algorithm>
  10.  
  11. #include<iostream>
  12.  
  13. #include<vector>
  14.  
  15. #include<map>
  16.  
  17. #include<set>
  18.  
  19. #include<queue>
  20.  
  21. #include<string>
  22.  
  23. #define inf 1000000000
  24.  
  25. #define maxn 200000+5
  26.  
  27. #define maxm 200000+5
  28.  
  29. #define eps 1e-10
  30.  
  31. #define ll long long
  32.  
  33. #define pa pair<int,int>
  34.  
  35. #define for0(i,n) for(int i=0;i<=(n);i++)
  36.  
  37. #define for1(i,n) for(int i=1;i<=(n);i++)
  38.  
  39. #define for2(i,x,y) for(int i=(x);i<=(y);i++)
  40.  
  41. #define for3(i,x,y) for(int i=(x);i>=(y);i--)
  42.  
  43. #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
  44.  
  45. #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
  46.  
  47. #define mod 1000000007
  48.  
  49. using namespace std;
  50.  
  51. inline int read()
  52.  
  53. {
  54.  
  55. int x=,f=;char ch=getchar();
  56.  
  57. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  58.  
  59. while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
  60.  
  61. return x*f;
  62.  
  63. }
  64. struct rec{int x,y;}a[maxn];
  65. int n;
  66. inline bool cmp(rec a,rec b){return a.x*b.y<b.x*a.y;}
  67.  
  68. int main()
  69.  
  70. {
  71.  
  72. freopen("input.txt","r",stdin);
  73.  
  74. freopen("output.txt","w",stdout);
  75.  
  76. n=read();
  77. for1(i,n)a[i].x=read();
  78. for1(i,n)a[i].y=read();
  79. sort(a+,a+n+,cmp);
  80. ll ans=,sum=;
  81. for1(i,n)
  82. {
  83. sum+=a[i].x;
  84. ans+=sum*(ll)a[i].y;
  85. }
  86. cout<<ans<<endl;
  87.  
  88. return ;
  89.  
  90. }

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. QQ炫舞官网选项卡效果

    这篇博文里需要注意的是当点击事件发生的时候,需要用循环,重置标题的classname和标题底部都设置成隐藏,当点击的时候在加上标题的active属性和显示属性 代码地址:https://github. ...

  2. C#: Create a WebRequest with HTTP Basic Authentication

    http://blog.csdn.net/huangyaoshifog/article/details/4470675 myReq = WebRequest.Create(url); string u ...

  3. C#中类型分析中的常见问题 Type - 转

    http://www.cnblogs.com/yuanyuan/archive/2012/08/16/2642281.html 写代码的时候经常需要分析已有类型的信息例如:分析现有类型自动生成类, 或 ...

  4. 使用maven多模块来构建系统时,spring初始化报错的问题

    最近在实验maven结构的maven工程时,碰到一个问题,springbean总是初始化失败: Related cause: org.springframework.beans.factory.Uns ...

  5. ContextLoaderListener作用详解(转)

    ContextLoaderListener监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在 ...

  6. 设计模式之单实例模式(Singleton)

    原理:将类的构造函数由pubic变为private或者protect,添加获取对象的public 成员函数,返回指向对象的静态指针. 首先来一段简单的代码实现 代码一 class Singleton ...

  7. linux文件系统创建文件的过程

    创建一个文件最主要的步骤就是: 1.为文件创建一个文件目录项. 2.为文件创建一个inode结构并分配inode号,将inode编号与文件名映射关系保存在1中分配的文件目录项中. 3.将1中创建的文件 ...

  8. 【块状树】BZOJ 1086: [SCOI2005]王室联邦

    1086: [SCOI2005]王室联邦 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 826  Solved:  ...

  9. 【POJ】【1704】Georgia and Bob

    组合游戏 Nim游戏的一个变形 题解请看金海峰的博客 以下为引用: 分析:我们把棋子按位置升序排列后,从后往前把他们两两绑定成一对.如果总个数是奇数,就把最前面一个和边界(位置为0)绑定. 在同一对棋 ...

  10. Matlab实现求a到b被c整除的个数

    我先想到的是for循环........ 然后sum(find(mod(a:b,c)==0)),从10到100得到874,为什么不对呢? 比如a = [1 2 3 4  2 3 4 2],find(a= ...