杭电5146题
来源:互联网 发布:数据分析师能力要求 编辑:程序博客网 时间:2024/06/04 00:33
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 thatAi≠Bi .
Now,give you the sequence A,check out it’s good or not.
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
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 integersA1,A2,…,An .
[Technical Specification]
1 <= T <= 100
1 <= n <= 1000
0 <=Ai <= 1000000
Each test case begins with a line contains an integer n,the length of sequence A.
The next line follows n integers
[Technical Specification]
1 <= T <= 100
1 <= n <= 1000
0 <=
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 <iostream>using namespace std;int x[1000000];int main(){int m,n,s1,s2;int i,j;cin >> m;while (m--){cin >> n;s1 = s2 = 0;for (i = 0; i < n; i++) {cin >> x[i];if(( i + 1 ) % 2 == 0) s2 += x[i];else s1 += x[i];}//判断数列奇数项和偶数项之和是否相等if(s1 == s2){s1 = s2 =0;for(i = 0, j = n - 1; i <= n / 2; i++, j--){s1 += x[i];s2 += x[j];} //判断是否为回文数列if(s1 == s2) cout << "No" << endl;else cout << "Yes" << endl;}else cout << "No" << endl;}return 0;}
(鄙人还是新手,代码写的比较烂。欢迎各位高手留言,对代码精简完善)
0 0
- 杭电5146题
- 杭电ACM1002题
- 杭电ACM1003题
- 杭电1004题
- 杭电1005题
- 杭电1012题
- 杭电1013题
- 杭电1014题
- 杭电1017题
- 杭电1032题
- 杭电1015题
- 杭电1020题
- 杭电1022题
- 杭电2023题
- 杭电1004题
- 杭电1005题
- 杭电1008题
- 杭电1007题
- 理解矩阵
- Spring 中一个常用的反射类库ReflectionUtils
- 30多年程序员生涯经验总结
- Speak loudly
- UNIX/Linux---ln 命令详解
- 杭电5146题
- 【leetcode SQL】Second Highest Salary
- httpclient3.x中使用HTTPS的方法
- 无缝滚动
- nodejs的一些问题理解
- UVa 10082 - WERTYU
- snmp编程特点小结
- 有喜有忧
- 不急不躁修硬盘