Bestcoder round #11 (Div. 2) question

Source: Internet
Author: User


Hdoj5054 Alice and Bob Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 302 accepted submission (s): 229


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)

/** * Created by ckboss on 14-10-3. */import java.util.*;public class Main {    public static void main(String[] args){        Scanner in = new Scanner(System.in);        while(in.hasNext())        {            int N=in.nextInt();            int M=in.nextInt();            int x=in.nextInt();            int y=in.nextInt();            if(x==N-x&&y==M-y)                System.out.println("YES");            else                System.out.println("NO");        }    }}


Hdoj5055 Bob and Math Problem Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 812 accepted submission (s): 313


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)

/** * Created by ckboss on 14-10-3. */import java.util.*;public class Main {    static int[] num = new int[10];    static char[] ans = new char[110];    static int nt;    public static void main(String[] args){        Scanner in = new Scanner(System.in);        int n;        while(in.hasNext()){            n=in.nextInt();            int flag=0;            int MinJ=111;            Arrays.fill(num,0); nt=0;            for(int i=0;i<n;i++){                int x=in.nextInt();                num[x]++;                if(x%2==1){                    if(x<MinJ) MinJ=x;                    flag++;                }            }            if(flag==0)            {                System.out.println("-1");                continue;            }            num[MinJ]--;            for(int i=9;i>=0;i--){                for(int j=num[i];j>0;j--){                    ans[nt++]=(char)('0'+i);                }            }            ans[nt++]=(char)(MinJ+'0');            flag=0;            for(int i=0;i<nt;i++){                if(ans[i]=='0' && flag==0){                    flag=0; break;                }                flag=1;                System.out.print(ans[i]);            }            if(flag==1)                System.out.println("");            else                System.out.println("-1");        }    }}


Hdoj5056 boring count Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 615 accepted submission (s): 242


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)
O (n) greedy...


/** * Created by ckboss on 14-10-3. */import java.util.*;public class Main {    static long[] num = new long[30];    public static void main(String[] args){        Scanner in = new Scanner(System.in);        int T_T=in.nextInt();        while(T_T-->0){            String st=in.next();            int k=in.nextInt();            Arrays.fill(num,0);            int be=0,ed=0;            long ans=0;            for(int i=0,sz=st.length();i<sz;i++){                int id=(int)(st.charAt(i)-'a');                num[id]++;                if(num[id]>k){                    for(;be<=ed;be++){                        ans+=ed-be+1;                        num[st.charAt(be)-'a']--;                        if(st.charAt(be)-'a'==id) {                            be++;                            break;                        }                    }                }                ed=i;            }            for(;be<=ed;be++){                ans+=ed-be+1;                num[st.charAt(be)-'a']--;            }            System.out.println(ans);        }    }}


Hdoj5057 argestes and Sequence Time Limit: 5000/2500 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 603 accepted submission (s): 152


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)

Good chunking methods ....


#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int maxn=100100;struct BLOCK{    int cnt[10][10];}block[400];int block_size,block_num;int n,m;int a[maxn];const int ten[12]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};void CHANGE(int p,int v){    int id=p/block_size;    int x=a[p];    for(int i=0;i<10;i++)    {        block[id].cnt[i][x%10]--;        x/=10;    }    a[p]=v;    x=v;    for(int i=0;i<10;i++)    {        block[id].cnt[i][x%10]++;        x/=10;    }}int QUERY(int l,int r,int p,int d){    int L=l/block_size,R=r/block_size;    int ans=0;    if(R-L<=1)    {        for(int i=l;i<=r;i++)        {            ans+=((a[i]/ten[p-1])%10==d)?1:0;        }        return ans;    }    for(int i=l;i<(L+1)*block_size;i++)    {        ans+=((a[i]/ten[p-1])%10==d)?1:0;    }    for(int i=L+1;i<=R-1;i++)    {        ans+=block[i].cnt[p-1][d];    }    for(int i=R*block_size;i<=r;i++)    {        ans+=((a[i]/ten[p-1])%10==d)?1:0;    }    return ans;}int main(){    int T_T;    scanf("%d",&T_T);    while(T_T--)    {        scanf("%d%d",&n,&m);        memset(block,0,sizeof(block));        block_size=sqrt(n*1.0)+1;        block_num=n/block_size+1;        for(int i=1;i<=n;i++)        {            scanf("%d",&a[i]);            int x=a[i];            int id=i/block_size;            for(int j=0;j<10;j++)            {                block[id].cnt[j][x%10]++;                x/=10;            }        }        while(m--)        {            char op[10];            int a,b,c,d;            scanf("%s",op);            if(op[0]=='Q')            {                scanf("%d%d%d%d",&a,&b,&c,&d);                printf("%d\n",QUERY(a,b,c,d));            }            else if(op[0]=='S')            {                scanf("%d%d",&a,&b);                CHANGE(a,b);            }        }    }    return 0;}





Bestcoder round #11 (Div. 2) question

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.