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

2020/8/10个人赛总结

Description of the game

昨晚打个人赛,打的是div2(我这只菜鸡只配打div2),一共A了7道题,这其中是有水题的,但是相对还不错,给大家分享几道我认为比较不错的题。

Problems

B - Paper Game

在这里插入图片描述在这里插入图片描述
题意:给一张nm的纸,最小剪成11的大小,找最多剪几下,根据剪得次数判断谁输谁赢。

思路:找规律,发现一张nm的·纸最多能剪nm-1下。

AC代码:

#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

在这里插入图片描述
在这里插入图片描述
题意 :用三个点i,j,k表示矩形,其中(i,0)为矩形的左下角的点,(j,k)为矩形的右上角的点,求所给的几个矩形的覆盖面积。

思路:用一个二维数组来存1*1小正方形,用小正方形右上角的顶点来存该面积,覆盖的话设为1,否则为0;

AC代码:

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

题意:连续输入几个数,判断从左到右最多有多少个公差为1的数。

思路:用一个数组记录每个数字出现的状态,然后递加,和最大值比较大小即可。

AC代码:

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

题意 :判断一个字符串是不是可以组成回文序列的字符串,并且输出相应的回文序列(必须按照字母的顺序)。

思路:暴力求解

AC代码:

#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;
}



总结

这次比赛难度稍小,有一些题目是暴力求解,有一些则需要用到dp,写代码的时候还是会有些粗心,导致一些小错误还要debug浪费了一些时间,英语读题能力还是需要提高的,加油!!!

猜你喜欢

转载自blog.csdn.net/rookie636/article/details/107926759
今日推荐