Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 925 Accepted Submission(s): 500
Problem Description
Today we have a number sequence A includes n elements.
Nero thinks a number sequence A is good only if the sum of its elements with odd index equals to the sum of its elements with even index and this sequence is not a palindrome.
Palindrome means no matter we read the sequence from head to tail or from tail to head,we get the same sequence.
Two sequence A and B are consider different if the length of A is different from the length of B or there exists an index i that Ai≠Bi .
Now,give you the sequence A,check out it’s good or not.
Nero thinks a number sequence A is good only if the sum of its elements with odd index equals to the sum of its elements with even index and this sequence is not a palindrome.
Palindrome means no matter we read the sequence from head to tail or from tail to head,we get the same sequence.
Two sequence A and B are consider different if the length of A is different from the length of B or there exists an index i that Ai≠Bi .
Now,give you the sequence A,check out it’s good or not.
Input
The first line contains a single integer T,indicating the number of test cases.
Each test case begins with a line contains an integer n,the length of sequence A.
The next line follows n integers A1,A2,…,An .
[Technical Specification]
1 <= T <= 100
1 <= n <= 1000
0 <= Ai <= 1000000
Each test case begins with a line contains an integer n,the length of sequence A.
The next line follows n integers A1,A2,…,An .
[Technical Specification]
1 <= T <= 100
1 <= n <= 1000
0 <= Ai <= 1000000
Output
For each case output one line,if the sequence is good ,output "Yes",otherwise output "No".
Sample Input
3 7 1 2 3 4 5 6 7 7 1 2 3 5 4 7 6 6 1 2 3 3 2 1
Sample Output
No Yes No
题意:给一个序列,如果奇数位之和等于偶数位并且不是回文序列则输出Yes,否则输出No
思路:直接模拟
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1010
int a[N];
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
long long suml=0,sumr=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(i&1) suml+=a[i];
else sumr+=a[i];
}
int flag=0;
if(suml!=sumr)
{
printf("No\n");
continue;
}
for(int i=1;i<=n;i++)
if(a[i]!=a[n-i+1])
flag=1;
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}