HDU5146Sequence
来源:互联网 发布:网络直播 分析评论 编辑:程序博客网 时间:2024/05/16 06:31
Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 863 Accepted Submission(s): 456
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
题目比较简单,Bestcode 里面的题目,看不懂题目意思的可以去看中文版的:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=557&pid=1001
题目意思:看给出的序列是好的还是坏的;
如何判断一个数列是好的还是坏的,题目中给的定义是:
该数列的奇数项和偶数项的和不相等,并且该数列不为回文数列(回文数列就是该数列正着看和倒着看是一样的);并且两个序列A和B被认为不同,当且仅当两个序列的长度或者存在某个位置a[i]!=b[i];
给出AC代码:
#include<iostream>using namespace std;int a[1000005], b[1000005], c[1000005];int main(){int t, n;int p, q;cin >> t;while (t--){p = 0;q = 0;cin >> n;int sum1, sum2;sum1 = 0;sum2 = 0;for (int i = 1; i <= n; i++){if (i % 2 == 1){cin >> a[p];c[i] = a[p];sum1 += a[p++];//将奇数项的数列累加起来}else if (i % 2 == 0){cin >> b[q];c[i] = b[q];sum2 += b[q++];//将偶数项的数列累加起来;}}int i, j;int flag1=1, flag2=0;if (p == q) {for ( i = p - 1, j = q - 1; i >= 0 && j >= 0; i--, j--) //判断奇数数列和偶数数列存在 a[i]!=b[i];{if (a[i] != b[j])flag1 = 1;}if (flag1 != 1)flag1 = 0;}else flag1 = 1;for (i = 1, j = n; i < n && j >= 1; i++, j--)//判断数列是否为回文串;{//cout << a[i] << " " << b[j] << endl;if (c[i] != c[j])flag2 = 1;}//cout << "sum1==" << sum1 << " " << "sum2==" << sum2 << endl;if (sum1 == sum2&&flag1&&flag2)cout << "Yes" << endl;else cout << "No" << endl;}return 0;}
1 0
- HDU5146Sequence
- Android应用开发allowBackup敏感信息泄露的一点反思
- ubuntu 环境变量文件
- 【ASP.NET】文件上传与时间戳的获取
- Android性能优化典范(1)(2)(3)
- 蓝天格锐生命环的使用方法
- HDU5146Sequence
- 关于ERM和SRM:简单的美才是真的美
- JavaScript中类型判断
- sql 链接
- oracle中的wm_concat函数以及over分析函数
- ubuntu14下整合eclipse和javah生成jni头文件遇到无法访问android.app.Activity 找不到android.app.Activity的类文件问题的解决方案
- windows软件-----办公效率提高
- mapreduce创建solrcloud索引
- VS 中出现没有可放置在工具箱上的组件解决方法