BC11hdoj5054&&hdoj5055&&hdoj5056&&hdoj5057

来源:互联网 发布:广州市软件创新人才 编辑:程序博客网 时间:2024/06/03 11:25

Alice and Bob

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 699    Accepted Submission(s): 508


Problem Description
Bob and Alice got separated in the Square, they agreed that if they get separated, they'll meet back at the coordinate point (x, y). Unfortunately they forgot to define the origin of coordinates and the coordinate axis direction. Now, Bob in the lower left corner of the Square, Alice in the upper right corner of the the Square. Bob regards the lower left corner as the origin of coordinates, rightward for positive direction of axis X, upward for positive direction of axis Y. Alice regards the upper right corner as the origin of coordinates, leftward for positive direction of axis X, downward for positive direction of axis Y. Assuming that Square is a rectangular, length and width size is N * M. As shown in the figure:

Bob and Alice with their own definition of the coordinate system respectively, went to the coordinate point (x, y). Can they meet with each other ? 
Note: Bob and Alice before reaching its destination, can not see each other because of some factors (such as buildings, time poor).
 

Input
There are multiple test cases. Please process till EOF. Each test case only contains four integers : N, M and x, y. The Square size is N * M, and meet in coordinate point (x, y). ( 0 < x < N <= 1000 , 0 < y < M <= 1000 ).
 

Output
If they can meet with each other, please output "YES". Otherwise, please output "NO".
 

Sample Input
10 10 5 510 10 6 6
 

Sample Output
YESNO
 

Source
BestCoder Round #11 (Div. 2)
 

#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<list>#include<queue>#include<vector>using namespace std;const int maxn=10010;int main(){    int n,m,x,y,i,j,k,t;    while(~scanf("%d%d%d%d",&n,&m,&x,&y)){        if(x==(n-x)&&y==(m-y))            printf("YES\n");        else             printf("NO\n");    }    return 0;}

Bob and math problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1395    Accepted Submission(s): 511


Problem Description
Recently, Bob has been thinking about a math problem.
There are N Digits, each digit is between 0 and 9. You need to use this N Digits to constitute an Integer.
This Integer needs to satisfy the following conditions:
  • 1. must be an odd Integer.
  • 2. there is no leading zero.
  • 3. find the biggest one which is satisfied 1, 2.

Example: 
There are three Digits: 0, 1, 3. It can constitute six number of Integers. Only "301", "103" is legal, while "130", "310", "013", "031" is illegal. The biggest one of odd Integer is "301".
 

Input
There are multiple test cases. Please process till EOF.
Each case starts with a line containing an integer N ( 1 <= N <= 100 ).
The second line contains N Digits which indicate the digit a1,a2,a3,,an.(0ai9).
 

Output
The output of each test case of a line. If you can constitute an Integer which is satisfied above conditions, please output the biggest one. Otherwise, output "-1" instead.
 

Sample Input
30 1 335 4 232 4 6
 

Sample Output
301425-1
 

#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;const int maxn=10010;int num[maxn];int main(){    int n,i,j,k,t;    while(~scanf("%d",&n)){        int odd=0,even=0,zero=0,omin=10,pos;        for(i=0;i<n;++i){            scanf("%d",&num[i]);            if(num[i]&1){                omin=min(omin,num[i]);odd++;            }            if(num[i]==0)zero++;            if(num[i]%2==0&&num[i])even++;        }        if(odd==0){            printf("-1\n");        }        else if(odd==1&&zero+odd==n&&zero){            printf("-1\n");        }        else {            sort(num,num+n);            for(i=n-1;i>=0;--i){                if(num[i]==omin)break;                printf("%d",num[i]);            }            for(j=i-1;j>=0;--j){                printf("%d",num[j]);            }            printf("%d\n",omin);        }    }    return 0;}

Boring count

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 886    Accepted Submission(s): 364


Problem Description
You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.
 

Input
In the first line there is an integer T , indicates the number of test cases.
For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.

[Technical Specification]
1<=T<= 100
1 <= the length of S <= 100000
1 <= K <= 100000
 

Output
For each case, output a line contains the answer.
 

Sample Input
3abc1abcabc1abcabc2
 

Sample Output
61521
 

Source
BestCoder Round #11 (Div. 2)
 

#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>using namespace std;const int maxn=100010;char str[maxn];int vis[26];int main(){    int t,i,j,k;    scanf("%d",&t);    while(t--){        scanf("%s%d",str,&k);        long long pos=0,ans=0;        int len=strlen(str);        memset(vis,0,sizeof(vis));        for(i=0;i<len;++i){            vis[str[i]-'a']++;            if(vis[str[i]-'a']>k){                while(vis[str[i]-'a']>k){                    vis[str[pos]-'a']--;pos++;                }            }            ans=ans+(i-pos+1);        }        printf("%lld\n",ans);    }    return 0;}

Argestes and Sequence

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 925    Accepted Submission(s): 262


Problem Description
Argestes has a lot of hobbies and likes solving query problems especially. One day Argestes came up with such a problem. You are given a sequence a consisting of N nonnegative integers, a[1],a[2],...,a[n].Then there are M operation on the sequence.An operation can be one of the following:
S X Y: you should set the value of a[x] to y(in other words perform an assignment a[x]=y).
Q L R D P: among [L, R], L and R are the index of the sequence, how many numbers that the Dth digit of the numbers is P.
Note: The 1st digit of a number is the least significant digit.
 

Input
In the first line there is an integer T , indicates the number of test cases.
For each case, the first line contains two numbers N and M.The second line contains N integers, separated by space: a[1],a[2],...,a[n]—initial value of array elements.
Each of the next M lines begins with a character type.
If type==S,there will be two integers more in the line: X,Y.
If type==Q,there will be four integers more in the line: L R D P.

[Technical Specification]
1<=T<= 50
1<=N, M<=100000
0<=a[i]<=231 - 1
1<=X<=N
0<=Y<=231 - 1
1<=L<=R<=N
1<=D<=10
0<=P<=9
 

Output
For each operation Q, output a line contains the answer.
 

Sample Input
15 710 11 12 13 14Q 1 5 2 1Q 1 5 1 0Q 1 5 1 1Q 1 5 3 0Q 1 5 3 1S 1 100Q 1 5 3 1
 

Sample Output
511501
 

Source
BestCoder Round #11 (Div. 2)
 

先写了个树状数组果断超内存了,看了别人的解题思路用分块法将连续的区间分成几块,当要区间求和时只需求出包含的大块和边缘的部分即可

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<list>#include<queue>#include<vector>using namespace std;const int maxn=100010;struct Node{    int cnt[11][10];}block[350];int block_size,block_num;int n,m;int num[maxn];int bit[11]={0,1,10,100,1000,10000,100000,100000,10000000,100000000,1000000000};void update(int pos,int y){    int id=pos/block_size;    for(int j=1;j<=10;++j){        block[id].cnt[j][num[pos]/bit[j]%10]--;        block[id].cnt[j][y/bit[j]%10]++;    }    num[pos]=y;}int sum(int l,int r,int d,int p){    int left=l/block_size,right=r/block_size,ans=0;    if(right-left<=1){        for(int i=l;i<=r;++i){            if(num[i]/bit[d]%10==p)ans++;        }        return ans;    }    for(int i=l;i<(left+1)*block_size;++i){        if(num[i]/bit[d]%10==p)ans++;    }    for(int i=left+1;i<=right-1;++i){        ans+=block[i].cnt[d][p];    }    for(int i=right*block_size;i<=r;++i){        if(num[i]/bit[d]%10==p)ans++;    }    return ans;}int main(){    int t,i,j,k;    scanf("%d",&t);    while(t--){        scanf("%d%d",&n,&m);        memset(block,0,sizeof(block));        block_size=sqrt(1.0*n)+1;        block_num=n/block_size+1;        for(i=1;i<=n;++i){            scanf("%d",&num[i]);            int id=i/block_size;            for(j=1;j<=10;++j){                block[id].cnt[j][num[i]/bit[j]%10]++;            }        }        char str[10];        while(m--){            scanf("%s",str);            if(str[0]=='S'){                int x,y;                scanf("%d%d",&x,&y);                update(x,y);            }            else {                int l,r,d,p;                scanf("%d%d%d%d",&l,&r,&d,&p);                printf("%d\n",sum(l,r,d,p));            }        }    }    return 0;}


0 0
原创粉丝点击