首页 > 代码库 > bestcoder#23 1001 Sequence

bestcoder#23 1001 Sequence

Sequence


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 712    Accepted Submission(s): 439


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 AiBi.
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
 
Output
For each case output one line,if the sequence is good ,output "Yes",otherwise output "No".
 
Sample Input
371 2 3 4 5 6 771 2 3 5 4 7 661 2 3 3 2 1
 
Sample Output
NoYesNo
 
#include <cstdio>#include <cmath>#include <cstring>#include <ctime>#include <iostream>#include <algorithm>#include <set>#include <vector>#include <sstream>#include <queue>#include <typeinfo>#include <fstream>typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 1005const int inf=0x7fffffff;   //无限大int a[maxn];int main(){    int n;    cin>>n;    while(n--)    {        //memset(a,0,sizeof(a));        int b;        scanf("%d",&b);        ll ans1=0;        ll ans2=0;        for(int i=0;i<b;i++)        {            scanf("%d",&a[i]);            if(i%2==0)                ans1+=a[i];            else                ans2+=a[i];        }        if(ans1!=ans2)            cout<<"No"<<endl;        else        {            int flag=0;            for(int i=0;i<b;i++)            {                if(a[i]!=a[b-i-1])                {                    flag=1;                    break;                }            }            if(flag==0)                cout<<"No"<<endl;            else                cout<<"Yes"<<endl;        }    }    return 0;}

 

bestcoder#23 1001 Sequence