- Time: 2016-04-17-16:35:01 Sunday
- Title Number: [2016-04-17][gym][100947][c][rotate It!]
- Topic: Given a column of numbers, from the first start to take, every other number to take a number, there is an operation is to put the first number in the last, can be unlimited operation, ask the maximum value is how much
- Analysis:
- Can be seen as a ring, each ring, can start from each ring, ask the maximum value is how much
- Number is an even number, very simple, is to find the odd position and the sum of the number of pairs of the maximum value
- Number is an odd number,
- Analysis can be known that there must be adjacent two numbers in the selected sequence, then only need to enumerate the adjacent two series, calculate the maximum value can be
- Example of a sample 1 5 3 2 4
- First 1 4 connected, then 15, one analogy,
- If you just look at the format of the sample, that is, 1 5 3 2 4, the adjacent two digits are i,j,
- Assuming I is in an odd position, then the answer becomes the sum of the I-front odd digits and the number of pairs after J.
- Even the same
- Problems encountered:
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1E4 + 10;
long long a[maxn],b[maxn];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,tmp;
long long s[2] = {0};
scanf("%d",&n);
if(!(n&1)){
for(int i = 0; i < n ; ++i){
scanf("%d",&tmp);
s[i&1] += tmp;
}
printf("%I64d\n",max(s[0],s[1]));
}else {
a [ 0 " = b [ 0 ] Span class= "pun" >= 0 ;
for(int i = 1 ; i <= n; ++i){
scanf("%d",&tmp);
if(i & 1){
a[i] = a[i - 1] + tmp;
b[i] = b[i - 1];
}else {
a[i] = a[i - 1];
b[i] = b[i - 1] + tmp;
}
}
long long ans = -1E4 * 1E9;
for(int i = 0 ; i < n ; ++i){
if(i & 1){
ans = max(ans , a[i] + b[n] - b[i]);
}
else{
ans = max(ans , b[i] + a[n] - a[i]);
}
}
printf("%I64d\n",ans);
}
}
return 0;
}
From for notes (Wiz)
[2016-04-17] [Gym] [100947] C [Rotate It!]