Codeforces731F Video Cards

考虑每个数在最大值内的倍数都求出来大概只有max(ai)ln(max(ai))个。

先排个序,然后对于每个数ai,考虑哪些数字可以变成ai*k。

显然就是区间[ai*k,ai*(k+1))内的数,这个二分一下就好了。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 int a[200010];
 5
 6 int main()
 7 {
 8     int n;
 9     scanf("%d", &n);
10     for (int i = 0; i < n; i++)
11         scanf("%d", a + i);
12     sort(a, a + n);
13     long long ans = 0;
14     int last = -1;
15     for (int i = 0; i < n; i++)
16     {
17         if (a[i] == last)
18             continue;
19         long long temp = 0;
20         for (int j = 0; (j - 1) * a[i] <= a[n - 1]; j++)
21         {
22             int down = j * a[i];
23             int up = (j + 1) * a[i];
24             int *pup = lower_bound(a, a + n, up);
25             int *pdown = lower_bound(a, a + n, down);
26             temp += 1LL * j * a[i] * (pup - pdown);
27         }
28         ans = max(ans, temp);
29         last = a[i];
30     }
31     printf("%I64d", ans);
32     return 0;
33 }
时间: 2024-10-28 21:58:25

Codeforces731F Video Cards的相关文章

Codeforces 731F Video Cards

题意:给定n个数字,你可以从中选出一个数A(不能对该数进行修改操作),并对其它数减小至该数的倍数,统计总和.问总和最大是多少? 题解:排序后枚举每个数作为选出的数A,再枚举其他数, sum += a[i]-a[i]%A;复杂度为O(n^2), 爆炸. 显然应该降至O(nlogn). 枚举每个数a[i]做为A,再枚举A的倍数j即可, sum += j*(lower_bound(a, a+n, j+a[i])-lower_bound(a, a+n, j)); 那么此时复杂度为O(nlognlogn)

Codeforces Round #376 (Div. 2) F. Video Cards

题解: 没想到是直接暴力求解..... 使用前缀和加速 代码: #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=1000100; int a[maxn],num[maxn]; int n,x; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&

Video processing systems and methods

BACKGROUND The present invention relates to video processing systems. Advances in imaging technology have led to high resolution cameras for personal use as well as professional use. Personal uses include digital cameras and camcorders that can captu

CentOS6.4安装ati显卡驱动

台式机安装CentOS 6.4 x86_64位  集成显卡ati4290 CentOS的release notes上: The proprietary drivers for older AMD ( former ATI ) video cards, namely the 2xxx, 3xxx and 4xxx series ( both integrated in motherboards or standalone cards) are not compatible with the new

Flexible implementation of a system management mode (SMM) in a processor

A?system?management?mode?(SMM) of operating a processor includes only a basic set of hardwired hooks or mechanisms in the processor for supporting SMM. Most of SMM functionality, such as the processing actions performed when entering and exiting SMM,

Checking the Performance of FindArray

FindArray Example Let's create a program that shows how a sample C++ compiler generates code for a function named FindArray. Later, we will write an assembly language version of the function, attempting to write more efficient code than the C++ compi

outdated: 21.Lines, Antialiasing, Timing, Ortho View And Simple Sounds

这是一个简单的小游戏,类型相当于amidar,不过也有1000行,手困眼花......UP\DOWN\LEFT\RIGHT控制,SPACE重新开始. 在TimerInit()函数中,QueryPerformanceFrequency()函数查询性能计数器的频率.QueryPerformanceCounter()函数查询性能计数器的当前值.两个函数的参数都用到了LARGE_INTEGER的强制转换.以前写过一篇介绍的文章. 在glPrint()函数里,新添了glScalef()函数(用缩放矩阵乘以

URAL 1313 Some Words about Sport (阅读理解)

1313 Some Words about Sport Time limit: 0.5 second Memory limit: 64 MB Ural doctors worry about the health of their youth very much. Special investigations showed that a lot of clever students instead of playing football, skating or bicycling had par

MarkDown的错误信息

Frequently Asked Questions General Questions What are the system requirements for MarkdownPad? Is there a portable version of MarkdownPad? What languages are available in MarkdownPad? Can I help translate MarkdownPad? Is the original version of Markd