Sequence

Sequence


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


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
水题!一个数组只要奇数项的和等于偶数项的和 并且满足不是回文数( Palindrome)
就输出Yes,否则输出No.就是英文题看的有点不舒服.
#include<iostream>
#include<cstdio>
#define N 1000001
int a[N];
using namespace std;
int main()
{
    int T,n,oddsum,evensum;
    int finish;
    cin>>T;
    while(T--)
    {
        finish=1;
        oddsum=0;evensum=0;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<n;i++)
        {
            if((i+1)%2==0){evensum+=a[i];}
            else {oddsum+=a[i];}
        }
        if(oddsum==evensum)
        {
            for(int i=0;i<n;i++)
            {
                for(int j=n-1;j>=0;j--)
                {
                    if(a[i]==a[j]) {finish=0;}
                    else {finish=1;}
                }
            }
            if(finish) {cout<<"Yes"<<endl;}
            else {cout<<"No"<<endl;}
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值