题意:给定 n 个数,可以对所有的数进行缩小,问你找出和最大的数,使得这些数都能整除这些数中最小的那个数。

析:用前缀和来做,先统计前 i 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段就好。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug puts("+++++")
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2e5 + 5;
const LL mod = 1e9 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
inline int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
inline int lcm(int a, int b){ return a * b / gcd(a, b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn];
int sum[maxn]; int main(){
while(scanf("%d", &n) == 1){
int x;
memset(a, 0, sizeof a);
for(int i = 0; i < n; ++i){
scanf("%d", &x);
++a[x];
}
for(int i = 1; i <= 200000; ++i) sum[i] = sum[i-1] + a[i];
LL ans = 0;
for(int i = 1; i <= 200000; ++i) if(a[i]){
LL tmp = 0;
int j;
for(j = i-1; j <= 200000; j += i)
tmp += (LL)(sum[j] - sum[j-i]) * (j+1-i);
if(j > 200000) tmp += (LL)(sum[200000]-sum[j-i]) * (j+1-i);
ans = Max(ans, tmp);
}
cout << ans << endl;
}
return 0;
}

CodeForces 731F Video Cards (数论+暴力)的更多相关文章

  1. Codeforces 731F Video Cards

    题意:给定n个数字,你可以从中选出一个数A(不能对该数进行修改操作),并对其它数减小至该数的倍数,统计总和.问总和最大是多少? 题解:排序后枚举每个数作为选出的数A,再枚举其他数, sum += a[ ...

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

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

  3. 【19.05%】【codeforces 731F】 Video Cards

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. 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 ...

  5. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...

  6. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  7. 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 ...

  8. Video Cards

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

  9. [CodeForces - 1225C]p-binary 【数论】【二进制】

    [CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 5 ...

随机推荐

  1. python之GUI图形用户界面 2014-4-7

    #图形用户界面1.下载和安装wxPython2.创建并显示一个框架import wx #导入wxPythonapp=wx.App()win=wx.Frame(None)win.Show() #调用窗口 ...

  2. linux & chmod & 777

    linux & chmod & 777 https://github.com/xgqfrms-GitHub/Node-CLI-Tools/blob/master/bash-shell- ...

  3. [luoguP1388] 算式(DP)

    传送门 看这个n<=15本以为是个状压DP 还是too young 这个题最神奇的地方是加括号是根据贪心的策略. 发现只有在一连串的加号两边加上括号才是最优的(想一想,为什么?) f[i][j] ...

  4. Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

    C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell ...

  5. 跨域请求Ajax(POST)处理方法

    getXSSAjax(function() {  //跨域请求        that.ajaxDara(self);}, (bs_tita.webapi || "http://webapi ...

  6. Linux中kill,pkill,killall和xkill命令汇总讲解

    终止一个进程或终止一个正在运行的程式,一般是通过 kill .killall.pkill.xkill 等进行.比如一个程式已死掉,但又不能退出,这时就应该考虑应用这些工具. 另 外应用的场合就是在服务 ...

  7. UVA 1347_Tour

    题意: 给定一系列按x坐标升序排列的点,一个人从左向右走到终点再从终点走回起点,要求每个点恰好经过一次,问所走过的最短路径长度. 分析: 可以看成是两个人同时从起点向终点走,且除起点终点外每个点恰有一 ...

  8. Ubuntu 16.04出现chmod: 无效模式:"a"的问题解决

    命令: chmod a+x file1 提示:注意文件的类型,如果用在文件夹上是不行的,但是文件确实可以的.

  9. 源码SDWebImage

    源码来源:https://github.com/rs/SDWebImage 版本: 3.7 SDWebImage是一个开源的第三方库,它提供了UIImageView的一个分类,以支持从远程服务器下载并 ...

  10. USB2.0的最高传输速率

    USB2.0除了拥有USB1.1中规定的1.5Mbps和12Mbps两个传输模式以外,还增加了480Mbps高速数据传输模式(注:第二版USB2.0的传输速率将达800Mbps,最高理想值1600Mb ...