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 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段 ...
随机推荐
- Json——使用Json jar包实现Json字符串与Java对象或集合之间的互相转换
总结一下利用Json相关jar包实现Java对象和集合与Json字符串之间的互相转换: 1.创建的User类: package com.ghj.packageofdomain; public clas ...
- php操作xml的方法
xml源文件 <?xml version="1.0 encoding="UTF-8"?> <humans> <zhangying> & ...
- FastDFS的配置、部署与API使用解读(2)以字节方式上传文件的客户端代码(转)
本文来自 诗商·柳惊鸿 Poechant CSDN博客,转载请注明源地址:FastDFS的配置.部署与API使用解读(2)上传文件到FastDFS分布式文件系统的客户端代码 在阅读本文之前,请您先通过 ...
- PostgreSQL源码解读 基础结构 node
一.node节点的定义 源代码路径postgresql-9.2.3/src/include/nodes/nodes.h 在查询解析SQL的查询部分,要用到大量的结构体,许多函数处理的逻辑类似,就是传入 ...
- grunt简单教程
Grunt简单教程 1.grunt简单介绍 Grunt是一个基于任务的命令行工具.依赖于node.js环境. 它能帮你合并js文件,压缩js文件,验证js.编译less,合并css.还能够配置自己主动 ...
- c++vector简单实现
const int DEFAULT_CAP = 3; template <typename T> class vector { // int capacity; T* _data; int ...
- Educational Codeforces Round 9 E. Thief in a Shop NTT
E. Thief in a Shop A thief made his way to a shop. As usual he has his lucky knapsack with him. Th ...
- Latex 5: LaTeX资料下载
转: LaTeX资料下载 最全latex资料下载 LaTeX命令速查手册1
- hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...
- js-easyUI格式化时间
formatter : function(value, row) { if(value != null){ var date = new Date(value); var y = date.getFu ...