概述
Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 887 Accepted Submission(s): 473
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.
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
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
Source
BestCoder Round #23
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=1010;
int num[maxn];
int main()
{
int t,i,j,k,n,m;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int odd=0,even=0;
for(i=1;i<=n;++i){
scanf("%d",&num[i]);
if(i&1)odd+=num[i];
else even+=num[i];
}
bool sign=false;
for(i=1;i<=n/2;++i){
if(num[i]!=num[n-i+1]){
sign=true;
}
}
if(sign&&odd==even){
printf("Yesn");
}
else {
printf("Non");
}
}
return 0;
}
Sequence II
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 967 Accepted Submission(s): 389
Problem Description
Long long ago, there is a sequence A with length n. All numbers in this sequence is no smaller than 1 and no bigger than n, and all numbers are different in this sequence.
Please calculate how many quad (a,b,c,d) satisfy:
1. 1≤a<b<c<d≤n
2. Aa<Ab
3. Ac<Ad
Please calculate how many quad (a,b,c,d) satisfy:
1. 1≤a<b<c<d≤n
2. Aa<Ab
3. Ac<Ad
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 next line follows n integers A1,A2,…,An .
[Technical Specification]
1 <= T <= 100
1 <= n <= 50000
1 <= Ai <= n
Each test case begins with a line contains an integer n.
The next line follows n integers A1,A2,…,An .
[Technical Specification]
1 <= T <= 100
1 <= n <= 50000
1 <= Ai <= n
Output
For each case output one line contains a integer,the number of quad.
Sample Input
1 5 1 3 2 4 5
Sample Output
4
Source
BestCoder Round #23
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=50010;
int num[maxn],c[maxn],n;
int low(int n){
return n&(-n);
}
int sum(int pos){
int value=0;
while(pos){
value+=c[pos];
pos-=low(pos);
}
return value;
}
void add(int p,int q){
while(p<=n){
c[p]+=q;
p+=low(p);
}
}
int main()
{
int t,i,j,k;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(c,0,sizeof(c));
long long ans=0,cnt=0,l,g;
for(i=1;i<=n;++i){
scanf("%d",&num[i]);
l=sum(num[i]);
g=n-num[i]-(i-1-l);
ans=ans+cnt*g;
cnt+=l;
add(num[i],1);
}
printf("%lldn",ans);
}
return 0;
}
最后
以上就是害羞毛衣为你收集整理的BC23&&hdoj5146&&hdoj5147SequenceSequence II的全部内容,希望文章能够帮你解决BC23&&hdoj5146&&hdoj5147SequenceSequence II所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复