【CUGBACM15级BC第23场 A】hdu 5146 Sequence
2017-08-21 21:06
330 查看
Sequence
[align=center]Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1031 Accepted Submission(s): 583
[/align]
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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
[align=left]Output[/align]
For each case output one line,if the sequence is good ,output "Yes",otherwise output "No".
[align=left]Sample Input[/align]
3
7
1 2 3 4 5 6 7
7
1 2 3 5 4 7 6
6
1 2 3 3 2 1
[align=left]Sample Output[/align]
No
Yes
No
题意:判断这个序列是不是好的,好的要求是在奇数坐标上的数的和等于在偶数坐标上的数的和且这个序列不是回文序列
#include<bits/stdc++.h> #include <ctime> using namespace std; typedef long long ll; const int MAXN = 1 * 1e5 + 500; const ll M = 1e9 + 7; int fun(int low, int high, int *str, int length) { if (length == 0 || length == 1) { return 1; } if (str[low] != str[high]) { return 0; } return fun(low + 1, high - 1, str, length - 2); } int a[1500]; int main() { ///clock_t start_time = clock(); ///clock_t end_time = clock(); ///cout << "Running time is: " << static_cast<double>(end_time - start_time) / CLOCKS_PER_SEC * 1000 << "ms" << endl; std::ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, sum1 = 0, sum2 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (i % 2 == 1) { sum1 += a[i]; } else { sum2 += a[i]; } } //cout << sum1 << endl; //cout << sum2 << endl; if (fun(0, n - 1, a, n) == 1 || sum1 != sum2) { cout << "No" << endl; } else { cout << "Yes" << endl; } } return 0; }
相关文章推荐
- 【CUGBACM15级BC第三场 B】hdu 4908 BestCoder Sequence
- 【CUGBACM15级BC第23场 B】hdu 5147 Sequence II
- 【CUGBACM15级BC第13场 B】hdu 5063 Operation the Sequence
- 【CUGBACM15级BC第8场 B】hdu 4990 Reading comprehension
- 【CUGBACM15级BC第29场 A】hdu 5170 GTY's math problem
- 【CUGBACM15级BC第11场 C】hdu 5056 Boring count
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation
- 【CUGBACM15级BC第20场 A】hdu 5123 who is the best?
- 【CUGBACM15级BC第21场 A】hdu 5138 CET-6 test
- 【CUGBACM15级BC第36场 B】hdu 5199 Gunner
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- 【CUGBACM15级BC第10场 A】hdu 5018 Revenge of Fibonacci
- 【CUGBACM15级BC第7场 B】hdu 4986 Little Pony and Alohomora Part I
- 【CUGBACM15级BC第22场 C】hdu 5144 NPY and shot
- 【CUGBACM15级BC第18场 A】hdu 5104 Primes Problem
- 【CUGBACM15级BC第20场 B】hdu 5124 lines
- 【CUGBACM15级BC第22场 B】hdu 5143 NPY and arithmetic progression
- 【CUGBACM15级BC第28场 A】hdu 5166 Missing number
- 【CUGBACM15级BC第35场 A】hdu 5194 DZY Loves Balls
- 【CUGBACM15级BC第9场 A】hdu 4993 Revenge of ex-Euclid