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 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段 ...
随机推荐
- vue2.0 自定义过滤器(filter)实例
一.过滤器简介 (1)过滤器创建 过滤器的本质 是一个有参数 有返回值的方法 new Vue({ filters:{ myCurrency:function(myInput){ return 处理后的 ...
- android studio——Could not find method externalNativeBuild()
gradle同步工程时出现错误 Error:(36, 0) Could not find method externalNativeBuild() for arguments [build_cazi7 ...
- Java 递归解决 "仅仅能两数相乘的计算器计算x^y" 问题
/** * 求一个数的乘方 * 求x^y,y是一个正整数. 设计算器仅仅能计算两数相乘,不能一次计算n个数相乘. * 知:2^5=(2^2)^2*2; 2^6=(2^2)^3=((4)^2)*4; 2 ...
- Eclipse打包Android项目时用到proguard.cfg后,出现的Warning:can't find referenced class问题的解决方式
Warning: can't find superclass or interface Warning: can't find referenced class 这两个问题的解决方法: 1.要把你项目 ...
- 使用JXL对EXCLE的导入导出
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Da ...
- CycleViewPager
https://github.com/zhaozhentao/CycleViewPager
- npm的常用配置
第一次使用需要初始化 npm init -y npm-tut { "requires": true, "lockfileVersion": 1, "d ...
- notepad++的f90配置文件
notepad++仅支持f77格式的,所以f90格式需要重新定义配置文件 传送门: http://ehc.ac/p/notepad-plus/discussion/331753/thread/8f72 ...
- python第三方库系列之十八--python/django test库
django是属于python语音的web框架,要说django測试.也能够先说说python的測试.django能够用python的方式測试,当然,django也基于python封装了一个自己的測试 ...
- 代码书写C++ 中调用传递与指针传递根本区别
从概念上讲.指针从本质上讲就是存放变量地址的一个变量,在逻辑上是独立的,它可以被改变,包括其所指向的地址的改变和其指向的地址中所存放的数据的改变.而引用是一个别名,它在逻辑上不是独立的,它的存在具有依 ...