贪心


就跟NOIP2012国王游戏差不多,考虑交换相邻两题的位置,对其他题是毫无影响的,然后看两题顺序先后哪个更优。sort即可。

WA了一次的原因:虽然ans开的是long long,但是在这一句:ans+=time*a[i].k;时,还是需要在time(int类型)前面加上(LL)进行类型强制转换。

 /**************************************************************
Problem: 3850
User: ProgrammingApe
Language: C++
Result: Accepted
Time:64 ms
Memory:2052 kb
****************************************************************/ //BZOJ 3850
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
const int N=;
typedef long long LL;
struct node{
int t,k;
bool operator < (const node& b) const {
return t*k+(t+b.t)*b.k < b.t*b.k+(t+b.t)*k;
}
}a[N]; int main(){
// freopen("input.txt","r",stdin);
int n;
scanf("%d",&n);
F(i,,n) scanf("%d",&a[i].t);
F(i,,n) scanf("%d",&a[i].k);
sort(a+,a+n+);
LL time=;
LL ans=;
F(i,,n){
time+=a[i].t;
ans+=(LL)a[i].k*time;
}
printf("%lld\n",ans);
return ;
}

【BZOJ】【3850】ZCC Loves Codefires的更多相关文章

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

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

  2. HDU-4882 ZCC Loves Codefires

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

  3. HDU 4882 ZCC Loves Codefires (贪心)

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

  4. HDU 4882 ZCC Loves Codefires(贪心)

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

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

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

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

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

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

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

  8. 【贪心】bzoj3850 ZCC Loves Codefires

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

  9. 【Bzoj 1835 基站选址】

    基站选址的区间里隐藏着DP优化的机密…… 分析:       不论是做过乘积最大还是石子合并,或者是其他的入门级别的区间DP题目的人呐,大米并认为读题后就能够轻松得出一个简洁明了的Dp转移方程.    ...

随机推荐

  1. Web Service无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分

    Web Service 无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置.请按名称指示首选的终结点配置部分   原因是在web.co ...

  2. XP极限编程

    13个核心实战  团队协作(Whole Team)  规划策略(The Planning Game) 软件发布计划(ReleasePlanning) 周期开发计划(IterationPlanning) ...

  3. IT新人论成长

    说自己是新人,其实自己也不新了,2012年毕业,辗转3个城市,现在在上海一家公司,工资不到5K. 在来现在公司之前,我从事web后台开发,采用MVC模式,虽然做了不少的网站,但感觉自己的水平还是在底层 ...

  4. Mongodb的索引--学习笔记(未完)

    全文索引 建立方法: --在articles集合的key字段上创建全文索引 db.articles.ensureIndex({key:"text"}) --在articles集合的 ...

  5. nandflash操作详解

    1.nandflash就是嵌入式系统的硬盘 2.分类(1)MLC:存储单元格存储两位,慢,偏移,寿命短,容量大(2)SLC:存储一位.快,寿命长,容量小,昂贵 3访问:(1)独立编址,有专用的控制器, ...

  6. 4.html5中超链接

    html中超链接都是通过<a>标签实现的,html5也不例外,这里就来探讨一下<a>标签. <a>元素属于文本元素,有一些私有属性或者叫局部属性.那么,相对应的还有 ...

  7. Python学习教程(learning Python)--2.3.5 Python返回多个值问题

    本节主要学习Python的函数是如何同时返回多个值的问题. 在学习Python的时候惊奇的发现,Python的函数可以同时返回多个值,很有意思. #define function sum def su ...

  8. rails bug

    variable @fontAwesomeEotPath_iefix is undefined rails generate bootstrap:install如果还有错,保证在加载主提之前impor ...

  9. 刀哥多线程之gcd-01-sync&async

    同步 & 异步 概念 同步 必须等待当前语句执行完毕,才会执行下一条语句 异步 不用等待当前语句执行完毕,就可以执行下一条语句 NSThread 中的 同步 & 异步 - (void) ...

  10. lnmp的使用

    命令 1.状态管理 lnmp {start|stop|reload|restart|kill|status} 2.添加虚拟host lnmp vhost add