【BZOJ】【3850】ZCC Loves Codefires

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

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

 1 /**************************************************************
 2     Problem: 3850
 3     User: ProgrammingApe
 4     Language: C++
 5     Result: Accepted
 6     Time:64 ms
 7     Memory:2052 kb
 8 ****************************************************************/
 9
10 //BZOJ 3850
11 #include<cstdio>
12 #include<cstring>
13 #include<cstdlib>
14 #include<iostream>
15 #include<algorithm>
16 #define rep(i,n) for(int i=0;i<n;++i)
17 #define F(i,j,n) for(int i=j;i<=n;++i)
18 #define D(i,j,n) for(int i=j;i>=n;--i)
19 using namespace std;
20 const int N=100086;
21 typedef long long LL;
22 struct node{
23     int t,k;
24     bool operator < (const node& b) const {
25         return t*k+(t+b.t)*b.k < b.t*b.k+(t+b.t)*k;
26     }
27 }a[N];
28
29 int main(){
30 //  freopen("input.txt","r",stdin);
31     int n;
32     scanf("%d",&n);
33     F(i,1,n) scanf("%d",&a[i].t);
34     F(i,1,n) scanf("%d",&a[i].k);
35     sort(a+1,a+n+1);
36     LL time=0;
37     LL ans=0;
38     F(i,1,n){
39         time+=a[i].t;
40         ans+=(LL)a[i].k*time;
41     }
42     printf("%lld\n",ans);
43     return 0;
44 }

时间: 2025-01-05 10:23:22

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

hdoj 4882 ZCC Loves Codefires 【贪心】

题目大意:求最少被扣除的时间 策略 如题: 对于两个邻近的题目i, j,对于他们对于在他们之前解决的题目的总时间的贡献t是不影响的,对于他们之后的总时间也不影响 这就推得对每一对相邻的他们对前后都是无影响的, 如果是交换的话原来是(t+e[i])*k[i] + (t+e[i]+e[j])*k[j], 就变成了(t+e[j])*k[j] + (t+e[i]+e[j])*k[i] 改变的就是 原来的 e[i]*k[j] 变成了 e[j]*k[i] 这两个式子之间满足 e[i]*k[j] < e[j]

P2433 - 【BZOJ 3262三维偏序】陌上花开------三维偏序

P2433 - [BZOJ 3262三维偏序]陌上花开 Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量. 定义一朵花A比另一朵花B要美丽,当且仅当Sa>=Sb,Ca>=Cb,Ma>=Mb.显然,两朵花可能有同样的属性.需要统计出评出每个等级的花的数量. Input 第一行为N,K (1 <= N <= 100,000, 1 <= K <= 200,

【BZOJ做题记录】07.07~?

在NOI一周前重开一个坑 最后更新时间:7.07 11:26 7.06 下午做的几道CQOI题: BZOJ1257: [CQOI2007]余数之和sum:把k mod i写成k-k/i*i然后分段求后面的部分就好了 BZOJ1258: [CQOI2007]三角形tri:在草稿纸上按照位置和边找一下规律就好了 BZOJ1260: [CQOI2007]涂色paint:简单的区间DP BZOJ1303: [CQOI2009]中位数图:小于中位数的改为-1大于的改为1,算一算前缀和然后哈希一下乘一乘就好

2014 (多校)1011 ZCC Loves Codefires

自从做了多校,整个人都不好了,老是被高中生就算了,题老是都不懂=-=原谅我是个菜鸟,原谅我智力不行.唯一的水题. Problem Description Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, called "Memset137". It was on Codefires(CF), an online competitive programming site, that ZCC knew Mems

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4882 ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

hdu 4882 ZCC Loves Codefires(贪心)

# include<stdio.h> # include <algorithm> # include <string.h> using namespace std; struct node { int v; int t; }; struct node a[100010]; bool cmp(node a,node b) { return a.v *a.t+(a.v+b.v)*b.t<b.v*b.t+(a.v+b.v)*a.t; } int main() { int

JAVA hdu 4882 ZCC Loves Codefires

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4882 题解:参考题后Discuss javaherongwei 的讲解 考察序列中相邻的两题i, j(i在前).交换它们后,解出它们之前的题目所带来的时间对答案的贡献是不变的,它们对它们后面的题目的贡献也是不变的,其他题目之间对答案的贡献自然也是不变的.唯一的变化就是,原来的EiKj一项变成了EjKi一项.那么,为了使答案变优,需要满足的条件是EjKi≤EiKj.也即Ei/Ki≥Ej/Kj.那么,最

hdu 4882 ZCC Loves Codefires(贪心)

题目链接:hdu 4882 ZCC Loves Codefires 题目大意:就是CF的比赛,根据时间的推迟会相应的扣掉题目的分数,问说最少扣几分. 解题思路:相邻交换法,判断两个题目之间的比率确定前后位置. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e5+5; typedef __int64 ll; struct st

HDOJ 4882 ZCC Loves Codefires

ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 198    Accepted Submission(s): 105 Problem Description Though ZCC has many Fans, ZCC himself is a crazy Fan of a coder, calle

HDU 4882 ZCC Loves Codefires(贪心水)

HDU 4882 ZCC Loves Codefires 题目链接 题意:给定一些任务,每个任务有e,k,e表示完成需要时间,k表示完成后消耗,为完成时间t * k,求一个顺序使得完成消耗最少 思路:贪心,知道k大的尽量早晚餐,t小的尽量早完成,所以t / k小的尽量早完成,排个序即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int