BZOJ3850: ZCC Loves Codefires
题目: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的更多相关文章
- 【贪心】bzoj3850 ZCC Loves Codefires
类似某noip国王游戏. 考虑交换两个题目的顺序,仅会对这两个题目的贡献造成影响. 于是sort,比较时计算两个题目对答案的贡献,较小的放在前面. #include<cstdio> #in ...
- 2014---多校训练2(ZCC Loves Codefires)
ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU-4882 ZCC Loves Codefires
http://acm.hdu.edu.cn/showproblem.php?pid=4882 ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 4882 ZCC Loves Codefires (贪心)
ZCC Loves Codefires 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/B Description Though ...
- HDU 4882 ZCC Loves Codefires(贪心)
ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4882 ZCC Loves Codefires(数学题+贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ------------------------------------------------ ...
- 2014 (多校)1011 ZCC Loves Codefires
自从做了多校,整个人都不好了,老是被高中生就算了,题老是都不懂=-=原谅我是个菜鸟,原谅我智力不行.唯一的水题. Problem Description Though ZCC has many Fan ...
- BZOJ 3850: ZCC Loves Codefires【贪心】
Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, called "Memset137". It wa ...
- 【BZOJ】3850: ZCC Loves Codefires(300T就这样献给了水题TAT)
http://www.lydsy.com/JudgeOnline/problem.php?id=3850 题意:类似国王游戏....无意义.. #include <cstdio> #inc ...
随机推荐
- SVN--下载、安装VisualSVN server 服务端和 TortoiseSVN客户端
前言: 在http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html的博客中已经很详细地介绍了SVN的服务器--VisualS ...
- 剑指offer--面试题16
#include<stack> //思路:遍历链表过程中,将各个指针入栈,再出栈进行反转 ListNode* ReverseList(ListNode* pHead) { if(pHead ...
- java中判空
一.概述 java中判等似乎很简单,==用来判断对象引用(内存地址)是否相同,equals用来判断值是否相同.你可以试用String对象轻松区分这一点. 那么在null判等(也就是判空操作)时呢? 可 ...
- SSAO
http://blog.csdn.net/xoyojank/article/details/5734537 http://john-chapman-graphics.blogspot.com/2013 ...
- [原] perforce 获取本地最近更新的Changelist
获取perforce客户端最后一次sync的changelist, 前提是中间没有任何代码提交: http://stackoverflow.com/questions/47007/determinin ...
- ADO.NET EF实体框架
ADO.NET 实体框架概述 随着.NET Framework 3.5 SP1和Visual Studio 2008 SP1的正式发布.ADO.NET 实体框架正式来到开发人员的面前,它使开发人员可以 ...
- [LeetCode]Link List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
- String类的使用 Part2
StringBuilder 类的使用 属性: namespace StringBuilderTest { class Program { static void Main(string[] args) ...
- hdu2011
http://acm.hdu.edu.cn/showproblem.php?pid=2011 #include<iostream> #include<math.h> #incl ...
- 数据类型演示DataTypeDemo
/***数据类型演示*/public class DataTypeDemo{ public static void main(String[] args){ //直接赋予的值,称为字面量 //by ...