cf 731 F. Video Cards (思维好题)
来源:互联网 发布:淘宝装修素材刚 编辑:程序博客网 时间:2024/04/30 02:36
Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated.
There are n video cards in the shop, the power of the i-th video card is equal to integer value ai. As Vlad wants to be sure the new game will work he wants to buy not one, but several video cards and unite their powers using the cutting-edge technology. To use this technology one of the cards is chosen as the leading one and other video cards are attached to it as secondary. For this new technology to work it's required that the power of each of the secondary video cards is divisible by the power of the leading video card. In order to achieve that the power of any secondary video card can be reduced to any integer value less or equal than the current power. However, the power of the leading video card should remain unchanged, i.e. it can't be reduced.
Vlad has an infinite amount of money so he can buy any set of video cards. Help him determine which video cards he should buy such that after picking the leading video card and may be reducing some powers of others to make them work together he will get the maximum total value of video power.
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of video cards in the shop.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 200 000) — powers of video cards.
The only line of the output should contain one integer value — the maximum possible total power of video cards working together.
43 2 15 9
27
48 2 2 7
18
In the first sample, it would be optimal to buy video cards with powers 3, 15 and 9. The video card with power 3 should be chosen as the leading one and all other video cards will be compatible with it. Thus, the total power would be 3 + 15 + 9 = 27. If he buys all the video cards and pick the one with the power 2 as the leading, the powers of all other video cards should be reduced by 1, thus the total power would be 2 + 2 + 14 + 8 = 26, that is less than 27. Please note, that it's not allowed to reduce the power of the leading video card, i.e. one can't get the total power 3 + 1 + 15 + 9 = 28.
In the second sample, the optimal answer is to buy all video cards and pick the one with the power 2 as the leading. The video card with the power 7 needs it power to be reduced down to 6. The total power would be 8 + 2 + 2 + 6 = 18.
题意:给你n个数,挑选一个基数, 基数*num,每个数最靠近这个数的部分相加。
思路:暴力枚举每个基数,每次在一段连续的区间找有多少个数。。 【基数,基数+基数】,【基数*2,基数*3】... 依次类推。
TEL点,注意判重,一串序列可能会存在相同的点。。。类似叫做剪枝吧
上代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;typedef long long ll;const int N = 900000+10;int pre[N],vis[N],a[N],flag[N];int main(){int n,i,j,Max;ll t,ans,sum;sum=0;scanf("%d",&n);Max=0;for(i=1;i<=n;i++) {scanf("%d",&a[i]);Max=max(Max,a[i]);vis[a[i]]++;sum+=a[i];}sort(a+1,a+1+n);for(i=1;i<=N;i++) {pre[i]=pre[i-1];pre[i]+=vis[i];}ans=0;if(a[1]==1) ans=sum;elsefor(i=1;i<=n;i++) {if(flag[a[i]]) continue;flag[a[i]]=1;t=0;for(j=a[i]+a[i];j<=Max;j=j+a[i]) {flag[j]=1;t+=(ll)(pre[j-1]-pre[j-a[i]-1])*(j-a[i]);}t+=(ll)(pre[j-1]-pre[j-a[i]-1])*(j-a[i]);ans=max(ans,t);}printf("%I64d\n",ans);return 0;}
- cf 731 F. Video Cards (思维好题)
- 【codeforces 731F】【前缀和 分块求和 好题】F. Video Cards
- Codeforce 731 F. Video Cards
- codeforces 731 F.Video Cards
- 【Codeforces 731 F Video Cards】
- 【19.05%】【codeforces 731F】 Video Cards
- Codeforces 731F Video cards 筛法
- CodeForces 731 F.Video Cards(水~)
- Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
- Codeforces Round #376 (Div. 2) F. Video Cards(前缀和,好题)
- Codeforces Round #376 (Div. 2) F Video Cards
- Codeforces Round #376 (Div. 2)F. Video Cards(乱搞)
- Video Cards
- cf(思维题)
- Vanya and Cards(CF结题报告)
- Codeforces Round #277.5(Div. 2) F. Special Matrices【思维+Dp】好题~好题~
- Codeforces Round #376 (Div. 2) F. Video Cards (二分)(lower bound)
- Codeforces Round #376 (Div. 2) F. Video Cards (数论 前缀和 分块求和)
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- UVA 10829 L-Gap Substrings (后缀数组+RMQ)
- js的模态窗口实例
- 离线宝API自定义换肤攻略
- python爬虫小项目:爬取百度贴吧图片
- cf 731 F. Video Cards (思维好题)
- cocos studio 初体验 版本3.10
- 1.pycharm使用心得 安装和首次使用 2016/11/6
- Ubuntu中如何将Tomcat端口改为80
- 使用hibernate创建相对应的数据库表(@注解配置)
- TCP/IP总结(一):概念讲述以及各层大致功能和协议
- bgslibrary视频前景提取算法之帧差法
- PHP - 类与面向对象(量略大)
- Mac终端使用技巧 切换到其他路径和目录