2020/08/10(B - Paper Game、C - Rectangles、D - Sequences、I - Playing With Strings)

2020/8/10 Individual Competition Summary

Description of the game

I played the individual match last night. I played div2 (my chicken is only equipped with div2). A total of 7 questions were asked. Among them, there are water questions, but they are relatively good. I will share with you a few questions I think. Good question.

Problems

B - Paper Game

Insert picture description hereInsert picture description here
Question: Give a piece of n m paper, cut it to the smallest size of 11, and find the most cuts, and judge who wins and who loses according to the number of cuts.

Idea: Find a pattern and find that a piece of n m paper can be cut at most n m-1.

AC code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    
    
    int n;
    scanf("%d",&n);
    while(n--)
    {
    
    
        long long int x,y;
        scanf("%lld %lld",&x,&y);
        if(x*y%2)printf("Hussain\n");
        else 
            printf("Hasan\n");
        
    }
    return 0;
}

C - Rectangles

Insert picture description here
Insert picture description here
Meaning of the question: Use three points i, j, k to represent the rectangle, where (i, 0) is the point at the lower left corner of the rectangle, (j, k) is the point at the upper right corner of the rectangle, find the number of rectangles given Covered area.

Idea: Use a two-dimensional array to store a 1*1 small square, and use the vertex at the upper right corner of the small square to store the area. Set it to 1 if it is overwritten, otherwise it is 0;

AC code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[110][110];
int main()
{
    
    
    int t;
    scanf("%d", &t);
    while (t--)
    {
    
    
        memset(a,0,sizeof(a));
        int n,i,sum=0;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
    
    
            int j,k;
            int x,y,z;
            scanf("%d %d %d",&z,&x,&y);
            for(j=z+1; j<=x; j++)
            {
    
    
                for(k=1; k<=y; k++)
                {
    
    
                    if(a[j][k]==0)
                    {
    
    
                        a[j][k]++;
                        sum++;
                    }
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

D - Sequences

One of the most wonderful qualities of an ACMer is to be multi interests so he combines multiple qualifications and hobbies not just coding. Hussain is one of the most qualified ACMers to mention when talking about hobbies and other domains of personality training despite of his qualifications in ACM problem solving and math. It's very known about Hussain his obsession in hunting and shooting, he used to pass hours training on empty cans in his childhood. These days, Hussain became a professional and still challenge others in this game, but for his bad luck he accidentally challenged a professional ACMer, without mentioning the name, so this ACMer made a game for Hussain. He numbered N targets for Hussain with random numbers and challenged him to shoot the minimum number of targets so the remaining numbers will form a sequence of increasing (by one) numbers in their current order. Example: if there is 6 targets numbered as follow: 2 5 7 3 2 4 Hussain will shoot 5,7 and the second 2 remaining for 2 3 4. Now, Hussain will focus on shooting, we will help him and focus on the targets he must shoot. But No! Hussain is an very good ACMer, we will make it hard for him and just tell him the number of the remaining targets in the sequence.

Input
First line contain an integer T represents the number of test cases 0 < T < 100, each test case consists of two lines, the first one is an integer 0< N < 20000 represents the number of targets, then followed by the second line that contains N numbers each number 0 < Xi < 20000 represents the number written on the i’th target.
Output
For each test case print one number represents the remaining sequence’s length can be created by the input where it should be the maximum length and each number of it follow its previous by 1.
Examples
Input

4
6
2 5 7 3 2 4
7
2 18 65 33 11 5 4
5
2 7 5 9 3
5
9 8 7 10 11

Output

3
1
2
3

Note

Please consider a large input file.

Meaning of the question: Enter several numbers in a row to determine how many numbers with a tolerance of 1 from left to right.

Idea: Use an array to record the state of each number, and then increment it, and compare the size with the maximum value.

AC code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[21000];
int main()
{
    
    
    int t;
    scanf("%d", &t);
    while (t--)
    {
    
    
        int n,i;
        scanf("%d", &n);
        int max = 0;
        memset(a, 0, sizeof(a));
        for (i = 0; i < n; i++)
        {
    
    
            int x;
            scanf("%d", &x);
            a[x] = 1;
            a[x] = a[x] + a[x - 1];
            if (max< a[x])
                max = a[x];
        }
        printf("%d\n", max);
    }
    return 0;
}

I - Playing With Strings

Dani and Mike are two kids ,They are playing games all day and when they don’t find a game to play they invent a game . There is about an hour to arrive to school, because they love playing with strings Dani invented a game , Given a string and the winner is the first who form a palindrome string using all letters of this string according to the following sample rules : 1- player can rearrange letters to form a string . 2- the formed string must be palindrome and use all letters of the given string. 3- if there is more than one string chose the lexicographically smallest string . EX: string is “abacb” player can form : “abcba” and “bacab” ,but “abcba” is the lexicographically smallest. Mike asked you to write a Program to compute the palindrome string so he can beat Dani.
Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1  ≤  T  ≤  1000). Every test case on one line contain one string ,the length of the string will not exceed 1000 lower case English letter.
Output

For each test case print a single line containing the lexicographically smallest palindrome string according to the rules above. If there is no such string print “impossible”
Examples
Input

4
abacb
acmicpc
aabaab
bsbttxs

Output

abcba
impossible
aabbaa
bstxtsb

Note

Palindrome string is a string which reads the same backward or forward.

Lexicographic order means that the strings are arranged in the way as they appear in a dictionary.

Question: Determine whether a string can form a palindrome sequence, and output the corresponding palindrome sequence (must be in alphabetical order).

Idea: Violent solution

AC code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[50];
int main()
{
    
    
    int t;
    scanf("%d", &t);
    getchar();
    while (t--)
    {
    
    
        int sum = 0,m=0;
        memset(a, 0, sizeof(a));
        char s[1010], b[1010], mid;
        scanf("%s", s);
        int l = strlen(s);
        for (int i = 0; i < l; i++)
            a[s[i] - 'a' + 1]++;
        if (l % 2 == 0)
        {
    
    
            for (int i = 1; i < 27; i++)
                if (a[i] % 2 == 1)
                    sum++;
            if (sum > 0)
                printf("impossible");
            else
            {
    
    
                for (int i = 1; i < 27; i++)
                    if (a[i] > 0)
                    {
    
    
                        a[i] = a[i] / 2;
                        while (a[i]--)
                        {
    
    
                            char c = i - 1 + 'a';
                            b[m++] = c;
                            printf("%c",c);
                        }
                    }
            }
            for (int i = m - 1; i >= 0; i--)
                printf("%c",b[i]);
        }
        else
        {
    
    
            for (int i = 1; i < 27; i++)
                if (a[i] % 2 == 1)
                    sum++;
            if (sum != 1)
                printf("impossible");
            else
            {
    
    
                for (int i = 1; i < 27; i++)
                    if (a[i] > 0)
                    {
    
    
                        if (a[i] % 2 == 1)
                        {
    
    
                            mid = i - 1 + 'a';
                            a[i]--;
                        }
                        if (a[i] % 2 == 0)
                        {
    
    
                            a[i] = a[i] / 2;
                            while (a[i]--)
                            {
    
    

                                char c = i - 1 + 'a';
                                b[m++] = c;
                                printf("%c", c);
                            }
                        }
                    }
                printf("%c", mid);
                for (int i = m - 1; i >= 0; i--)
                    printf("%c",b[i]);
            }
        }
        printf("\n");
    }
    return 0;
}



to sum up

This competition is a little less difficult. Some questions are violently solved, and some require dp. When writing code, there is still a little carelessness, which leads to some minor errors and wastes some time for debugging. English reading ability still needs to be improved. Yes, come on! ! !

Guess you like

Origin blog.csdn.net/rookie636/article/details/107926759