zoukankan      html  css  js  c++  java
  • hdu 5146(水题)

    Sequence

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


    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
     
    Source
     
    题意:给一个串,如果这个串奇数位之和等于偶数位之和并且不是回文串输出Yes,否则输出No
    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include <stdlib.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int N = 1005;
    int n,a[N];
    bool test1(){
        LL sum1 = 0,sum2 = 0;
        for(int i=1;i<=n;i+=2){
            sum1+=a[i];
        }
        for(int i=2;i<=n;i+=2){
            sum2+=a[i];
        }
        if(sum1==sum2) return true;
        return false;
    }
    bool test2(){
        for(int i=1,j=n;i<j;i++,j--){
            if(a[i]!=a[j]) return true;
        }
        return false;
    }
    int main()
    {
        int tcase;
        scanf("%d",&tcase);
        while(tcase--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
            }
            if(test1()&&test2()) printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
  • 相关阅读:
    解决maven构建webapp index.jsp报错问题
    Maven入门介绍
    Linux常用命令的解释
    linux怎么查看一个文件夹的大小
    EPEL源-是什么全称
    nginx+php-fpm配置后页面显示空白的解决方法(yum形式的安装)
    配置新服务器 的一些 依赖库 php mysql nginx
    服务器 CentOS上yum安装Nginx服务
    Java File创建新目录和文件
    struts2的文件上传
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5670670.html
Copyright © 2011-2022 走看看