Codeforces731F Video Cards
考虑每个数在最大值内的倍数都求出来大概只有max(ai)ln(max(ai))个。
先排个序,然后对于每个数ai,考虑哪些数字可以变成ai*k。
显然就是区间[ai*k,ai*(k+1))内的数,这个二分一下就好了。
#include <bits/stdc++.h>
using namespace std; int a[]; int main()
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", a + i);
sort(a, a + n);
long long ans = ;
int last = -;
for (int i = ; i < n; i++)
{
if (a[i] == last)
continue;
long long temp = ;
for (int j = ; (j - ) * a[i] <= a[n - ]; j++)
{
int down = j * a[i];
int up = (j + ) * a[i];
int *pup = lower_bound(a, a + n, up);
int *pdown = lower_bound(a, a + n, down);
temp += 1LL * j * a[i] * (pup - pdown);
}
ans = max(ans, temp);
last = a[i];
}
printf("%I64d", ans);
return ;
}
Codeforces731F Video Cards的更多相关文章
- 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 ...
- Video Cards
Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- 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 ...
- 【19.05%】【codeforces 731F】 Video Cards
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 731 F. Video Cards(前缀和)
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces 731F Video Cards
题意:给定n个数字,你可以从中选出一个数A(不能对该数进行修改操作),并对其它数减小至该数的倍数,统计总和.问总和最大是多少? 题解:排序后枚举每个数作为选出的数A,再枚举其他数, sum += a[ ...
- Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力
http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...
- CodeForces 731F Video Cards (数论+暴力)
题意:给定 n 个数,可以对所有的数进行缩小,问你找出和最大的数,使得这些数都能整除这些数中最小的那个数. 析:用前缀和来做,先统计前 i 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段 ...
随机推荐
- poj1870--Bee Breeding(模拟)
题目链接:点击打开链接 题目大意:给出一个蜂窝,也就是有六边形组成,从内向外不断的循环(如图).给出两个数的值u,v按六边形的走法,由中心向六个角走.问由u到v的的最小步数. 首先处理处每个数的坐标, ...
- js 日期 (10 + '').length == 10 ? '0' + 10 : 10;
js 日期 (10 + '').length == 10 ? '0' + 10 : 10;
- Elasticsearch 之 慘痛部署(分片移位)
部署说明 硬件 server两台: 机器A:64G内存 机器B:32G内存 分片 共12个节点 2个查询节点.10个存储节点 8个主分片 1个复制分片(每一个分片都有一个副本分布在不同的节点上面) 每 ...
- 爬虫-UserAgent
废话不多说,直接写代码 [root@localhost ~]# pip3 install fake-useragent Collecting fake-useragent Downloading ht ...
- python day- 16 面向对象
1.类的相关知识 类:是指具有相同属性和技能的一类事物. 比如:人类 ,植物类,动物类,狗类. 对象:是类中的某一个实例,是类的具体表现. 比如:具体到某个人,某一个植物,某一条狗. class 是p ...
- Multitier architecture
Multitier architecture - Wikipedia https://en.wikipedia.org/wiki/Multitier_architecture Common layer ...
- td 中连续数字或连续英文内容不自动换行
原因: 把连续的英文当做成了一个单词. 解决: 加上 : word-break: break-all (允许单词内换行)
- HDU 5651xiaoxin juju needs help
xiaoxin juju needs help Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- SVN命令使用详解【转】
本文转载自:http://blog.sina.com.cn/s/blog_963453200101eiuq.html 1.检出svn co http://路径(目录或文件的全路径) [本地目录全路 ...
- hdu 1514 Free Candies 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1514 题目意思:有4堆糖果,每堆糖果有n个,从上到下排好,取糖果只能从上往下取,取完的糖果放在篮子里, ...