HDU 5146 Sequence 回文数组
来源:互联网 发布:个性域名大全 编辑:程序博客网 时间:2024/06/14 17:02
原题: http://acm.hdu.edu.cn/showproblem.php?pid=5146
题目:
Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 762 Accepted Submission(s): 396
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.
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 <iostream>#include"cstdio"#include"string.h"#include"vector"using namespace std;const int N = 1005;int a[N];int n,m;int main(){ int tt; scanf("%d",&tt); while(tt--) { int sum1=0; int sum=0; scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d",&a[i]); if(i%2==1) sum1=sum1+a[i]; sum=sum+a[i]; } int flag=1; if(sum1*2==sum) { for(int i=1,j=n; i<=j; i++,j--) if(a[i]!=a[j]) { flag=0; break; } } if(flag==0) printf("Yes\n"); else printf("No\n"); }}
- HDU 5146 Sequence 回文数组
- HDU 5146 Sequence 判断序列不是回文 且奇数与偶数位的和不同
- hdu 5146 Sequence
- hdu 5146 Sequence
- hdu 5146 Sequence
- HDU 5146 Sequence
- hdu 1513 滚动数组优化 回文串
- hdu 1513 Palindrome 回文 LCS 滚动数组
- hdu 5147 Sequence II(树状数组)
- HDU 5147 Sequence II 树状数组
- hdu 5147 Sequence II(树状数组)
- HDU 5147 Sequence II 树状数组
- HDU 5147 Sequence II 枚举+树状数组
- 回文数组
- hdu 3948 后缀数组统计不同回文串的个数
- hdu 1513 Palindrome (滚动数组处理回文串)
- hdu 4441 Queue Sequence (伸展树splay+树状数组)
- hdu 5057 Argestes and Sequence(树状数组)
- zoj1203Swordfish(最小生成树)
- thml5 学习笔记(10)
- HDU 1542 Atlantis(线段树扫描线·面积并)
- 分割字符串
- C/C++中的const与define
- HDU 5146 Sequence 回文数组
- UIViewController
- java基础------数组
- JavaScript基础学习之-JavaScript权威指南-第二章词法结构
- 八 理解各种不同含义的new和delete
- python中的map、filter、reduce函数
- 抽象类和抽象方法
- Session的生命周期
- HDU 5373 The shortest problem