Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
来源:互联网 发布:大数据的特点是什么 编辑:程序博客网 时间:2024/05/16 12:55
题意:
给一个n长度的序列,问从序列中找一个数作为第一个数,把不小于它的数变成它或者它的倍数(不是他的倍数时只能减小成为他的倍数),并使得这些数的和最大。
题解:
首先记录每个数出现次数,这个数组处理前缀和,然后对所有数进行排序,从前到后枚举每个数成为第一个数,然后枚举倍数j,找到在这个数j倍-j+1倍的数目,这些数最终都变成了第一个数的j倍,然后求和取最大就可以了。
注意要去重。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>using namespace std;typedef long long ll;const int MAXN=200000+100;int a[MAXN],pre[MAXN*2];int main(){memset(pre,0,sizeof(pre));int n;scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]),pre[a[i]]++;for(int i=1;i<=MAXN*2;i++) pre[i]=pre[i-1]+pre[i];sort(a+1,a+n+1);int m=unique(a+1,a+n+1)-a-1; ll ans=0;for(int i=1;i<=m;i++){ll tmp=0;for(int j=2;(j-1)*a[i]<=a[m];j++){int p=(j-1)*a[i],q=j*a[i];tmp+=(ll)(pre[q-1]-pre[p-1])*a[i]*(j-1);}ans=max(ans,tmp);}printf("%I64d\n",ans);return 0;}
0 0
- Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
- Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
- Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和
- Codeforces Round #376 (Div. 2) F. Video Cards (数论 前缀和 分块求和)
- Codeforces Round #376 (Div. 2) F. Video Cards 数论+数据结构+前缀和
- Codeforces Round #376 (Div. 2) F Video Cards
- Codeforces Round #376 (Div. 2)F. Video Cards(乱搞)
- 【codeforces 731F】【前缀和 分块求和 好题】F. Video Cards
- Codeforces Round #376 (Div. 2) F. Video Cards (二分)(lower bound)
- Codeforces Round #376 (Div. 2)F(前缀和,模拟)
- Codeforces Round #394 (Div. 2) F. Dasha and Photos(二位前缀和+线段树/二维前缀和,好题)
- Codeforces Round #353 (Div. 2) C. Money Transfers 环、贪心、前缀和推广、好题
- Codeforces Round #394 (Div. 2) F. Dasha and Photos 二维前缀和 矩阵神器
- codeforces 731 F.Video Cards
- 【Codeforces 731 F Video Cards】
- Codeforces Round #227 (Div. 2)---E. George and Cards(贪心, 树状数组+set维护, 好题!)
- Codeforces Round #385 (Div. 2) E. Hongcow Buys a Deck of Cards DP+好题
- Codeforces Round #277.5(Div. 2) F. Special Matrices【思维+Dp】好题~好题~
- java经典多线程面试题
- 让IE6/IE7/IE8浏览器支持CSS3属性
- codeforces 377D exam贪心判定+二分
- Android Studio导入Eclipse项目和一些常见的问题
- python RuntimeError: dictionary changed size during iteration
- Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
- NO.1 Anaconda2 搭建 openCV
- 马尔可夫随机场(MRF)
- git———study
- emgucv相机标定
- STM32 IAP 在线升级详解
- JAVA开发3--将开发的java项目导出为jar包
- c# 获取 摄像头 实现录像
- dubbo管理台的部署