码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5146 Sequence

时间:2015-06-29 20:16:45      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5146

Sequence

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 $A_{i}\neq B_{i}.$
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 $A_{1},A_{2}, \ldots, A_{n}$

[Technical Specification]
1 <= T <= 100
1 <= n <= 1000
0 <= $A_{i}$ <= 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

手速题。。。

技术分享
 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 using std::cin;
10 using std::cout;
11 using std::endl;
12 using std::find;
13 using std::sort;
14 using std::set;
15 using std::map;
16 using std::pair;
17 using std::vector;
18 using std::multiset;
19 using std::multimap;
20 #define pb(e) push_back(e)
21 #define sz(c) (int)(c).size()
22 #define mp(a, b) make_pair(a, b)
23 #define all(c) (c).begin(), (c).end()
24 #define iter(c) decltype((c).begin())
25 #define cls(arr,val) memset(arr,val,sizeof(arr))
26 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
27 #define rep(i, n) for (int i = 1; i <= (int)(n); i++)
28 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
29 const int Max_N = 1010;
30 typedef unsigned long long ull;
31 int arr[Max_N];
32 int main() {
33 #ifdef LOCAL
34     freopen("in.txt", "r", stdin);
35     freopen("out.txt", "w+", stdout);
36 #endif
37     int t, n;
38     ull sum1, sum2;
39     scanf("%d", &t);
40     while (t--) {
41         bool f = false;
42         sum1 = sum2 = 0;
43         scanf("%d", &n);
44         rep(i, n) {
45             scanf("%d", &arr[i]);
46             if (i & 1) sum1 += arr[i];
47             else sum2 += arr[i];
48         }
49         if (sum1 != sum2) { puts("No"); continue; }
50         for (int i = 1, j = n; i < j; i++, j--) {
51             if (arr[i] != arr[j]) { f = true; break; }
52         }
53         puts(f ? "Yes" : "No");
54     }
55     return 0;
56 }
View Code

hdu 5146 Sequence

标签:

原文地址:http://www.cnblogs.com/GadyPu/p/4608207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!