码迷,mamicode.com
首页 > 其他好文 > 详细

bestcoder#23 1001 Sequence

时间:2014-12-21 10:18:28      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:

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
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
 
#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 1005
const 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

标签:

原文地址:http://www.cnblogs.com/qscqesze/p/4176205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!