BC23&&hdoj5146&&hdoj5147

来源:互联网 发布:s7200cn密码破解软件 编辑:程序博客网 时间:2024/06/11 16:30

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 AiBi.
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
 


 

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
 


 

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("Yes\n");        }        else {            printf("No\n");        }    }        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. 1a<b<c<dn
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
 


 

Output

 

For each case output one line contains a integer,the number of quad.
 


 

Sample Input

 

151 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("%lld\n",ans);    }    return 0;}


 

0 0
原创粉丝点击