swjtu 2385 Maximize The Beautiful Value
来源:互联网 发布:c语言 最长单词 编辑:程序博客网 时间:2024/05/18 10:52
Maximize The Beautiful Value
发布时间: 2017年5月14日 19:26 最后更新: 2017年5月14日 19:30 时间限制: 2000ms 内存限制: 128M
Today
To make it,
The first line contains an positive integer
For each test case:
The first line contains two positive integers
The second line contains
For each test case, you should output the max
35 31 1 3 4 55 21 1 3 4 55 11 1 3 4 5
465053
In the first example, you can move the fifth number
You can also move the fifth number to make it become [
In the second example, you can move the fifth number
In the second example, you can move the second number
scanf is commended。
题意:输入n,k,总共n个数,并且这n个数是非减的;选择一个数字最少要向前移动k个数,然后求出移动后的值;问移动哪一个数能够使得值为最大;求值:i*a[i] (i:1~n);
思路:因为这n个数是非减的,列出几个样例就可以知道只向前移动k步是最优的,不能再向前多移动,否则值会减小;开辟三个数组:a[]:本来的数,b[]:对a[]的前缀和;c[i]:i*a[i];S[i]:对c[]的前缀和;注意:处理的前缀和b[0]=0,S[0]=0;将数列分为3部分,比如n== 9,k==2;我们将第6个数向前移动k位应该是这样:
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=100005;typedef long long ll;ll a[maxn],b[maxn],c[maxn];ll S[maxn];int main(){ int T; scanf("%d",&T); while(T--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(S,0,sizeof(S)); int n,k; scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); b[i]=b[i-1]+a[i]; c[i]=i*a[i]; S[i]=S[i-1]+c[i]; }// for(int i=1;i<=n;i++)// printf("%lld ",b[i]);// printf("\n");// for(int i=1;i<=n;i++)// printf("%lld ",c[i]);// printf("\n");// for(int i=1;i<=n;i++)// printf("%lld ",S[i]);// printf("\n"); ll ans=0,sum1=0,sum2=0,sum3=0,sum=0; for(int i=k+1;i<=n;i++) { sum1=S[i-k-1]; sum2=S[i-1]-S[i-k-1]+b[i-1]-b[i-k-1]+c[i]-k*a[i]; sum3=S[n]-S[i];//printf("%lld %lld %lld \n",sum1,sum2,sum3); sum=sum1+sum2+sum3;// printf("%lld\n",sum); ans=max(sum,ans); } printf("%lld\n",ans); } return 0;}
- swjtu 2385 Maximize The Beautiful Value
- swjtuoj 2385 Maximize The Beautiful Value
- swjtu2385(Maximize The Beautiful Value)
- 西南交通大学第十三届ACM决赛 F.Maximize The Beautiful Value【思维】
- Maximize the Lifetime Value of a Social Game Player
- The 9th SWJTU-CPC Qualification Round Tutorials
- The 3rd ACM-ICPC Summer Training Contest(swjtu)
- The Beautiful Sentences
- The Beautiful Path
- The buji particularly beautiful sunset
- The Most Beautiful Equation (Remix)
- Tutorials for The 10th SWJTU Collegiate Programming Contest - Qualification Round
- Tutorials for The 10th SWJTU Collegiate Programming Contest - Online Round
- Stock Maximize
- Beautiful
- Hangzhou, the most beautiful city in China.
- The Principles of Beautiful Web Design [ILLUSTRATED]
- Careercup Facebook Keep the number beautiful...
- C#项目编译报“LC.exe已退出,代码为-1错误”解决办法
- redis 的学习路线
- Maven初识(三)——Maven的常用命令(插件),生命周期
- 【教程】InstallShield使用完全教程
- 解决win7无法更新defender(错误提示无法定义更新)
- swjtu 2385 Maximize The Beautiful Value
- 推荐两款实用的json数据请求及处理插件
- phpStudy出现You don't have permission to access / on this server.
- Python标准模块——argparse
- 移动前端UI框架使用
- C#中StringBuilder类的使用总结
- hdu 1009 FatMouse' Trade
- MyBatis取得新插入数据的ID
- word2Vec