贪心


就跟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. Knockout.Js官网学习(click绑定)

    前言 click绑定在DOM元素上添加事件句柄以便元素被点击的时候执行定义的JavaScript 函数.大部分是用在button,input和连接a上,但是可以在任意元素上使用. 简单示例 <h ...

  2. Yii整合ZF2及soap实例

    一)如何整合? // change the following paths if necessary $yii = dirname(__FILE__).'/framework/yii.php'; $c ...

  3. Show or Hide Menu List via ng-show

    <div ng-app ng-controller='MenuController'> <ul ng-show='menuState_show'> <li>Stun ...

  4. mysql数据库开发规范

    对规范的遵守可用二八原则,不要教条.为满足实际需求 可忽视部分规范. 1.索引规范 *目标 |--利用最小的索引成本找到需要的行记录 *原则 |--做前缀匹配 |--选择区分度高的列做前缀索引列 |- ...

  5. 一幅图证明chrome的由来和目的

  6. 文件系统 第八次迭代 VFS相关说明

    麻烦访问evernote链接 http://www.evernote.com/shard/s133/sh/53e5b5ac-1192-4910-8bd5-6886218562af/59516c32a5 ...

  7. RMAN 报:ORA-19504 ORA-27038

    在itpub中看到下面的问题: oracle 10g备份脚本如下run{allocate channel d1 device type disk MAXPIECESIZE=100M;crosschec ...

  8. flask-cors 实现跨域请求

    安装:pip install -U flask-cors from flask import Flask from flask.ext.cors import CORS app = Flask(__n ...

  9. c++大数模板

    自己写的大数模板,参考了小白书上的写法,只是实现了加减乘法,不支持负数,浮点数.. 除法还没写o(╯□╰)o以后再慢慢更吧.. 其实除法我用(xie)的(bu)少(lai),乘法写过fft,这模板还是 ...

  10. 部署git server

    http://gogs.io/docs/installation/install_from_binary.htmlwget http://gogs.dn.qbox.me/gogs_v0.6.5_lin ...