BestCoder Round #64 1002
Sum
There is a number sequenceA1,A2....An,you can select a interval [l,r] or not,all the numbers Ai(l≤i≤r) will become f(Ai).f(x)=(1890x+143) mod 10007f(x)=(1890x+143)mod10007.After that,the sum of n numbers should be as much as possible.What is the maximum sum?
There are multiple test cases. First line of each case contains a single integer n.(1≤n≤10^5) Next line contains (0≤Ai≤10^4) It's guaranteed that ∑n≤106.
For each test case,output the answer in a line.
2
10000 9999
5
1 9999 1 9999 1
19999
22033 我们可以把所有的数都尝试的换一下,但是需要一个变量记录增长量,我们取增长量最大的加上初始的和就行
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int a[100010];
int main()
{
int n;
int i,j;
__int64 sum,ans,Loli;
int b;
while(~scanf("%d",&n))
{
sum=0;Loli=0;ans=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
// cout<<sum<<endl;
for(i=0;i<n;i++)
{
if((a[i]*1890+143)%10007>a[i])
{
ans+=(a[i]*1890+143)%10007-a[i];
}
else if((a[i]*1890+143)%10007<=a[i])
{
ans-=a[i]-(a[i]*1890+143)%10007;
}
if(ans>Loli)
{
Loli=ans;
}
if(ans<0)
{
ans=0;
}
// cout<<ans<<endl;
}
if(Loli>0)
{
printf("%I64d\n",Loli+sum);
}
else
{
printf("%I64d\n",sum);
}
}
return 0;
}
BestCoder Round #64 1002的更多相关文章
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [f(n ...
- (BestCoder Round #64 (div.2))Array
BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...
- Manacher BestCoder Round #49 ($) 1002 Three Palindromes
题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...
- 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil
题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...
- hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]
传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131 ...
- ACM学习历程—HDU5586 Sum(动态规划)(BestCoder Round #64 (div.2) 1002)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 题目大意就是把一段序列里面的数替换成f(x),然后让总和最大. 首先可以计算出初始的总和,以及每 ...
- BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)
今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...
随机推荐
- git pull没有指定branch的报错
执行git pull或者git push的时,有时候会出现如下报错: $ git pull You asked me to pull without telling me which branch y ...
- day70-oracle PLSQL_01基本语法
PLSQL是一种程序,和java一样都是一种程序. sql developer是基于java的jdbc连接数据库.根据java的jdbc,只要有数据库的驱动,就可以连接这个数据库.这个工具默认不需要任 ...
- R: 判别分析
判别与聚类的比较: 聚类分析和判别分析有相似的作用,都是起到分类的作用. 判别分析是已知分类然后总结出判别规则,是一种有指导的学习: 聚类分析则是有了一批样本,不知道它们的分类,甚至连分成几类也不知道 ...
- Git 之 github分享代码
作为一个技术人员还是脱离不了屌丝的本质,所以每天都是逛逛github,看看别人有什么好的项目,自己可以给他挑挑bug也可以提供自己的水平,但是别人不那怎么才能给别人贡献代码呢?那就是fork了.... ...
- latex中的空格
两个quad空格 a \qquad b 两个m的宽度 quad空格 a \quad b 一个m的宽度 大空格 a\ b 1/3m宽度 中等空格 a\;b 2/7m宽度 小空格 a\,b 1/6m宽度 ...
- 缓存淘汰算法之LRU
1. LRU1.1. 原理 LRU(Least recently used,最近最少使用)算法根据数据的历史访问记录来进行淘汰数据,其核心思想是“如果数据最近被访问过,那么将来被访问的几率也更高”. ...
- Oracle中的学习笔记
1.使用 ||来连接字符串 select CARD_ID ||','||CARD_TYPE as qqq from CARDS t 2.DISTINCT (唯一不重复) select DISTINCT ...
- CentOS使用NTFS-3G加载NTFS硬盘
CentOS使用NTFS-3G加载NTFS硬盘 CentOS 挂载NTFS格式硬盘时会报错unknown filesystem type 'ntfs',这时就需要用到第三方的插NTFS-3G来加载NT ...
- 读取url接口数据
string url = "http://localhost:8180/city-smscenter/smscenter?cmd=flowsms.queryMobileSmsList& ...
- c++内联 inline
内联声明只是建议 ,不一定就会内联. http://www.voidcn.com/blog/u011327981/article/p-5006835.html