Bestcoder round #11 (Div. 2) question set

Source: Internet
Author: User
Alice and Bob Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 155 accepted submission (s): 110


Problem descriptionbob 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 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 ction 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 ).
Inputthere 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 ).
Outputif 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
 
Sourcebestcoder round #11 (Div. 2)
Recommendheyang | we have carefully selected several similar problems for you: 5053 5052 5051 5050 question: Tell you the length and width of a rectangle area. Then there are two coordinate systems. One is the origin in the lower left corner. The top right is in the positive direction. The origin is displayed in the upper-right corner. Bottom right is in the positive direction. Now I will give you a coordinate (x, y) and ask you if they represent the same point in the two coordinate systems. Idea: Convert different coordinate systems to the same coordinate system. I want to convert the upper left corner to the lower right corner. For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<stdio.h>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100010;typedef long long ll;int main(){    int n,m,x,y;    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): 456 accepted submission (s): 169


Problem descriptionrecently, 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 the odd integer is "301 ".
Inputthere 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 $ A_1, A_2, A_3, \ cdots, a_n. (0 \ Leq a_ I \ Leq 9) $.
Outputthe 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
 
Sourcebestcoder round #11 (Div. 2)
Recommendheyang | we have carefully selected several similar problems for you: 5053 5052 5051 5050 5049 question: give you n numbers to make up the largest odd number of N digits. If not, output-1. Thought: start to read the incorrect question. The output does not have to use all numbers. So I got down after the verdict. I really don't know how to get started with data... The greedy structure of this question is enough. First, find the smallest odd number for a single position. If not, use-1. Then sort the remaining number. If there are still numbers and the maximum value is 0, the output must be-1. If not, output the data in descending order and add the odd number that will be found. For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<stdio.h>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100010;typedef long long ll;int arr[150],brr[150];int main(){    int n,i,p,ct;    while(~scanf("%d",&n))    {        ct=0,p=-1;        for(i=0;i<n;i++)        {            scanf("%d",&arr[i]);            if(arr[i]&1)            {                if(p==-1||arr[i]<arr[p])                    p=i;            }        }        if(p==-1)        {            printf("-1\n");            continue;        }        for(i=0;i<n;i++)            if(i!=p)                brr[ct++]=arr[i];        sort(brr,brr+ct);        if(ct&&brr[ct-1]==0)        {            printf("-1\n");            continue;        }        for(i=ct-1;i>=0;i--)            printf("%d",brr[i]);        printf("%d\n",arr[p]);    }    return 0;}

Boring count Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 250 accepted submission (s): 98


Problem descriptionyou 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.
Inputin 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 <= length of S <= 100000
1 <= k <= 100000
Outputfor each case, output a line contains the answer.
Sample Input
3abc1abcabc1abcabc2
 
Sample output
61521
 
Sourcebestcoder round #11 (Div. 2)
Recommendheyang | we have carefully selected several similar problems for you: 5053 5052 5051 5050 question: give you a string of up to 1 E5 characters consisting of lowercase letters. Ask you how many substrings it has. The number of occurrences of each character meeting the substring cannot exceed K. Idea: For a left endpoint le that meets the conditions. Add the characters of the right endpoint Ri one by one. If the conditions are still met. This newly added character will contribute ri-le + 1 substring with this sub-character as the right endpoint. If the condition is not met, the left-shift le pointer knows that the condition is met. I thought of the train of thought long before the competition. Various logic errors may occur for 1 hour + 1A. For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<stdio.h>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100002;typedef long long ll;char txt[maxn];int vis[27];ll ans=0;int main(){    int t,n,k,le,ri,p;    scanf("%d",&t);    while(t--)    {        scanf("%s%d",txt,&k);        n=strlen(txt);        ans=le=ri=0;        memset(vis,0,sizeof vis);        p=-1;        while(ri<=n)        {            if(p==-1)            {                vis[txt[ri]-'a']++;                if(vis[txt[ri]-'a']>k)                    p=ri;                else if(ri<n)                    ans+=ri-le+1;                ri++;            }            else            {                vis[txt[le]-'a']--;                if(txt[le]==txt[p])                    p=-1,ans+=ri-le-1;                le++;            }        }        printf("%I64d\n",ans);    }    return 0;}

Argestes and Sequence Time Limit: 5000/2500 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 192 accepted submission (s): 44


Problem descriptionargestes 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 shoshould 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.
Inputin 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] <= $2 ^ {31} $-1
1 <= x <= N
0 <= Y <= $2 ^ {31} $-1
1 <= L <= r <= N
1 <= d <= 10
0 <= P <= 9
Outputfor 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
 
Sourcebestcoder round #11 (Div. 2)
Recommendheyang | we have carefully selected several similar problems for you: 5053 5052 5051 5050 question: Give You A series of length not more than 1 E5. You can perform two operations. 1. S x Y. Convert the number X to Y. 2. q l r d p. Ask the number D in [L, R] as the number of P. Ideas:
See this question. Overjoyed. Today is the rhythm of AK. (I don't know if 1002 will go down .. -- | ). Application of typical line segment tree. Each node has an array Val [RT] [I] [J]. Indicates the number of J in the interval represented by the node. Then I wrote it happily. Compile and run it once. The test sample without any errors or warnings is completely correct! Then I handed in happily. And then MLE... It was silly. Check the question memory limit. Dizzy. There is actually a Data Structure question card memory. Then I thought about opening 1 E7 space in the tree array, even short, but I thought about modifying and querying each bit offline. But now it is 20: 20. We vaguely remember that we were about to start hack. I gave up the struggle. Later, I realized that I still had no time to change it. Although the solution has the offline processing I mentioned. However, I always think it is quite troublesome to use block-based writing. It is divided into SQRT (n) blocks. Block direct violence. Blocks use the entire information to maintain and quickly calculate the answer. Time complexity O (N * SQRT (n )). After writing a transaction, rank1. The estimated O (10 * n * log (N) is too constant. For details, see the code:
#include<algorithm>#include<iostream>#include<string.h>#include<stdio.h>#include<math.h>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100003;typedef long long ll;#define lson L,mid,ls#define rson mid+1,R,rsint val[maxn][11],da[400][11][10],x;int main(){    int t,n,m,i,j,le,ri,d,p,x,y,bk,ans,st,ed,lim;    char cmd[10];    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        bk=ceil(sqrt(1.0*n));        memset(da,0,sizeof da);        memset(val,0,sizeof val);        for(i=1;i<=n;i++)        {            scanf("%d",&x);            for(j=1;j<=10;j++)            {                val[i][j]=x%10;                x/=10;            }            p=(i-1)/bk;            for(j=1;j<=10;j++)                da[p][j][val[i][j]]++;        }        for(i=0;i<m;i++)        {            scanf("%s",cmd);            if(cmd[0]=='Q')            {                scanf("%d%d%d%d",&le,&ri,&d,&p);                ans=0;                st=(le-1)/bk;                ed=(ri-1)/bk;                if(ed-st<=1)                {                    for(j=le;j<=ri;j++)                        if(val[j][d]==p)                            ans++;                }                else                {                    lim=(st+1)*bk;                    for(j=le;j<=lim;j++)                        if(val[j][d]==p)                            ans++;                    lim=ed*bk+1;                    for(j=lim;j<=ri;j++)                        if(val[j][d]==p)                            ans++;                    for(j=st+1;j<ed;j++)                        ans+=da[j][d][p];                }                printf("%d\n",ans);            }            else            {                scanf("%d%d",&x,&y);                p=(x-1)/bk;                for(j=1;j<=10;j++)                {                    if(y%10!=val[x][j])                    {                        da[p][j][val[x][j]]--;                        val[x][j]=y%10;                        da[p][j][val[x][j]]++;                    }                    y/=10;                }            }        }    }    return 0;}


Bestcoder round #11 (Div. 2) question set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.