题目链接:http://codeforces.com/contest/731/problem/F

题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的倍数,否则就舍弃掉,然后把没有舍弃的数的值加起来,求和的最大值;

4
3 2 15 9 就拿这个来说,当拿3当做第一个数时结果是3+15+9=27因为2不是3的倍数;当拿2作为第一个数时,结果是2+2+14+8=26因为3,15,9都不是2的倍数,所以只能减小;同理...求最大的和; 我们可以记录每个数出现的次数,然后记录前缀和,然后枚举每个数作为第一个数,当x作为第一个数时,我们可以枚举x的整数倍,然后每次找到整数j倍和j+1倍中的数出现了几次,这些数都是数x的j倍,然后求出对当前结果的贡献即可
时间复杂度为O(nlogn);
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define mod 1000000007
typedef long long LL;
//////////////////////////////////////////////////////////////
const int INF = 0x3f3f3f3f;
const int N = ;
const double eps = 1e-; int n, a[N];
LL pre[N*]; int main()
{
while(scanf("%d", &n)!=EOF)
{
met(pre, );
for(int i=; i<n; i++)
{
scanf("%d", &a[i]);
pre[a[i]]++;
} sort(a, a+n);
int m = unique(a, a+n) - a; for(int i=; i<=a[m-]*; i++)
pre[i] += pre[i-]; LL ans = ;
for(int i=; i<m; i++)
{
LL ret = ;
for(int j=; a[i]*(j+) <= a[m-]*; j++)
{
LL cnt = pre[(j+)*a[i]-] - pre[j*a[i]-];
ret += a[i]*j * cnt;
}
ans = max(ans, ret);
}
printf("%lld\n", ans);
}
return ;
}
 

Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)的更多相关文章

  1. Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和

    题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...

  2. Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力

    http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...

  4. Codeforces Round #552 (Div. 3) F. Shovels Shop (前缀和预处理+贪心+dp)

    题目:http://codeforces.com/contest/1154/problem/F 题意:给你n个商品,然后还有m个特价活动,你买满x件就把你当前的x件中最便宜的y件价格免费,问你买k件花 ...

  5. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  6. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  7. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  8. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  9. Codeforces Round #490 (Div. 3) :F. Cards and Joy(组合背包)

    题目连接:http://codeforces.com/contest/999/problem/F 解题心得: 题意说的很复杂,就是n个人玩游戏,每个人可以得到k张卡片,每个卡片上有一个数字,每个人有一 ...

随机推荐

  1. ibatis插入数据返回ID的方法

    ibatis插入数据返回ID的方法 主要就是利用seelctkey来获取这个ID值,但是oracle和mysql的区别还是很大的 oracle的用法 <insert id="inser ...

  2. 使用RBTool自动提交code review请求

    使用RBTool自动提交code review请求 前言 让我们回想一下手工提交review请求的过程: 首先得用 svn diff > filename.diff 生成diff文件. 然后输入 ...

  3. JAVA String.format 方法使用介绍

    1.对整数进行格式化:%[index$][标识][最小宽度]转换方式        我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解, ...

  4. 分支语句:if

    (1)分支语句if: if(判断条件) { 满足条件要执行的语句(若满足则alert输出(“”)) } else { 不满足条件时执行的语句 } (若if满足,else绝对不走,反之,走else) 例 ...

  5. bundle的理解笔记

    Bundle是一个键值对这样一个东西.就是一个string类型的东西,对应任何类型的东西.就是用来存值的. 这里可以看到他的作用 public void onClick(View v) { Strin ...

  6. php函数描述及例子

    /** * xml2array() will convert the given XML text to an array in the XML structure. * Link: http://w ...

  7. PHP对于Session漏洞的防范

    目前,基于PHP的网站开发已经成为目前网站开发的主流,本文笔者重点从PHP网站攻击与安全防范方面进行探究,旨在减少网站漏洞,希望对大家有所帮助! 一.常见PHP网站安全漏洞 对于PHP的漏洞,目前常见 ...

  8. centeros iptable模板文件

    iptables规则是空的.而且他们的selinux是关闭了的,这等同于把系统裸奔(总比windows裸奔好).   使用方法: 1.用root用户登录后 vi /etc/sysconfig/ipta ...

  9. Windows系统中Git的安装配置

    一.Git安装 1.下载 Git官网:https://git-scm.com/download/ 选择windows版本下载即可. 百度软件中心:http://rj.baidu.com/ 如官网下载不 ...

  10. POJ 1185 经典状压dp

    做了很久的题 有注释 #include<stdio.h> #include<string.h> #include<algorithm> #include<ma ...