BestCoder Round #64 (div.2) 1002 and 1003
来源:互联网 发布:ncs刷机软件 编辑:程序博客网 时间:2024/05/15 19:21
Sum
http://acm.hdu.edu.cn/showproblem.php?pid=5586
Problem Description
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)mod10007 .After that,the sum of n numbers should be as much as possible.What is the maximum sum?
Input
There are multiple test cases.
First line of each case contains a single integer n.(1≤n≤105)
Next line contains n integersA1,A2....An .(0≤Ai≤104)
It's guaranteed that∑n≤106 .
First line of each case contains a single integer n.
Next line contains n integers
It's guaranteed that
Output
For each test case,output the answer in a line.
Sample Input
210000 999951 9999 1 9999 1
Sample Output
1999922033
分析:原数组之和加上增量数组的最大连续子区间之和#include <iostream>#include <cstdio>using namespace std;const int N=1e5+10;int a[N];int b[N];typedef long long LL;LL sum[N];LL max(LL a,LL b){ if(a>b) return a; else return b;}int main() //(1890x+143)mod10007{ //freopen("cout.txt","w",stdout); int n,c; while(cin>>n){ LL y=0; for(int i=0;i<n;i++){ scanf("%d",&c); int r=(1890*c+143)%10007; b[i]=r-c; a[i]=c; y+=c; } LL summ=0,maxm=0; for ( int i = 0 ; i < n ; i++ ){ summ = max(0,summ)+b[i]; maxm = max(maxm,summ); } printf("%lld\n",y+maxm); } return 0;}Array
http://acm.hdu.edu.cn/showproblem.php?pid=5587
Vicky is a magician who loves math. She has great power in copying and creating.
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle '0' to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.
Input
There are multiple test cases.
First line contains a single integer T, means the number of test cases.(1≤T≤2∗103)
Next T line contains, each line contains one interger M. (1≤M≤1016)
Output
For each test case,output the answer in a line.
Sample Input
3
1
3
5
Sample Output
1
4
7学好递归是很有必要的!
0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 3 4 2 3 3 4 3 4 4 5……
红色区域第四层:
数字:1 2 3 4
个数:1 3 3 1
第五层:
数字:1 2 3 4 5
个数:1 4 6 4 1
数字个数和杨辉三角相关,前N+1层数字一共有个,10^16小于1<<50,那么用递归的话while循环求出各层数字和加上递归调用最坏结果:50+X*50 可以满足时间限制。
#include <iostream>#include <cstdio>using namespace std;typedef long long LL;LL work(LL m){ LL ans=1,cnt=1; while(1>0){ if(cnt==m) return ans; if(cnt==m-1) return ans+1; if(2*cnt+1>m){ ans=ans+m-cnt; ans=ans+work(m-cnt-1); return ans; } ans=2*ans+cnt+1; cnt=2*cnt+1; }}int main(){ int t; cin>>t; LL m; while(t--){ scanf("%I64d",&m); printf("%I64d\n",work(m)); } return 0;}
0 0
- BestCoder Round #64 (div.2) 1002 and 1003
- BestCoder Round #64 (div.2) 1003Array
- BestCoder Round #79 (div.2) 1002 Claris and XOR
- BestCoder Round #64 (div.2)
- BestCoder Round #64 (div.2)
- BestCoder Round #64 (div.2) 1003 Array HDU 5587
- BestCoder Round #50 (div.2) 1003
- BestCoder Round #63 (div.2)1003matrix
- BestCoder Round #57 (div.2)1002
- BestCoder Round #61 (div.2) 1002
- BestCoder Round #73 (div.2)1002/hdoj5631
- hdu5587 BestCoder Round #64 (div.2)
- hdu5586 BestCoder Round #64 (div.2)
- BestCoder Round #64 (div.2) Sum
- BestCoder Round #11 (Div. 2) Argestes and Sequence (hdu 5057)
- BestCoder Round #11 (Div. 2)--Bob and math problem
- BestCoder Round #52 (div.2) 1001 Victor and Machine
- BestCoder Round #52 (div.2) Victor and Machine
- java基础随笔-for each对于二维数组的处理
- hdu 1151 最小覆盖路径算法证明
- MySQL事务隔离级别详解
- Aptana简介与安装及其firebug的安装
- 我看Java虚拟机(3)---类文件结构
- BestCoder Round #64 (div.2) 1002 and 1003
- 野指针产生原因及解决办法
- [Sort]选择排序
- 趣学Python-教孩子学编程--第六章
- (NO.00004)iOS实现打砖块游戏(九):游戏中小球与反弹棒的碰撞
- 交叉编译和交叉调试环境的搭建及使用
- Android-SQLite3_1-下载和安装SQLite
- Mac Os X Yosemite 10.10.5 配置apache,php,mysql
- 学习笔记(1)——用户/用户组权限