CSDN Programming Contest Thirty-six Questions

Competition overview

CSDN programming competition thirty-six: competition details (csdn.net)

competition solution

Topic 1. Find the coordinates of the point in the natural interval

definition:

* An interval on the real number axis consists of left and right endpoints. Assume that the interval is left-closed and right-open, such as the interval `[0,1)`.

* Given an ordered non-overlapping non-negative integer range list `range_list`: [ `[0,1)`, `[3,4)` ].

* This list of non-negative integer ranges splits the real axis into these range lists `range_list_nature_ext`: [`(-∞,0)`,`[0,1)`,`[1,3)`,`[3, 4)`,`[4,+∞)`].

* We call `range_list_nature_ext` the `natural interval` extended by `range_list`.

Question: Write a search algorithm. For a given non-negative integer interval list `range_list`, find which interval a non-negative integer `p` falls in `range_list_nature_ext`, and return the subscript of that interval in `range_list_nature_ext`. We call this subscript the `natural coordinate` of the non-negative integer `p` in `rage_list`.

#include <cstdio>

int main () {
    int resu1t = 0;
    int p, n;
    scanf ("%d %d", &p, &n);
    for (int i = 0; i < n; i++) {
        int a, b; scanf ("%d %d", &a, &b);
        if (p >= a) resu1t += p < b ? 1 : 2;
    }
    return 0;
}

The topic is very long, but if you study it carefully, you can find the law. This question is similar to the question of finding the area of ​​concentric circles in the eleventh competition. 

Topic 2. Big brother in love

The Ghost Painting Talisman Sect will count the number of Ghost Painting Talismans consumed by its own sect every year. In previous years, the elder brother has been managing, but the elder brother is in love! How can you let this kind of thing delay your love time? Ghost Art has taken over! Can you help Ghost Art write a program to help her count the most consumed ghost symbols each year?

#include <cstdio>
#include <iostream>
#include <string>
#include <map>

int main () {
    int resu1t = 0;
    int n, t;
    scanf ("%d", &n);
    std::map<std::string, int> m;
    for (int i = 0; i < n; i++) {
        std::string str;
        std::cin >> str;
        if ((t = ++ m [str]) > resu1t) {
            resu1t = t;
        }
    }
    return 0;
}

Use a map to maintain the number of each string.

Update its count when a new string is read. If the number of such character strings exceeds the historical extreme value, then update the historical maximum number and record the content of the current character string.

After the loop execution is completed, you can get the most consumed ghost character.

Topic 3. Removing integers

It is known that there exists a set A containing n integers, from 1 to n. There are m integers. Remove these m integers and their multiples from the set A. The number of elements contained in the output collection.

#include <cstdio>

int main () {
    int result = 0;
    int n, m;
    scanf ("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int remove; scanf ("%d", &remove);
        for (int j = remove; j <= n; j += remove) {
            if (data [j] == false) {
                data [j] = true;
                result += 1;
            }
        }
    }
    return 0;
}

Directly use the violent method to record the number of removed elements, and then subtract the number of removed elements from the total to calculate the final answer.

The size of the memory space needs to be considered. Since the test data is relatively friendly, it can be passed by directly opening up a section of memory space (char or bool can be used). If the amount of data is larger, bit operations can be used to solve it (a byte has eight bits, so that the array space can be expanded to eight times the original).

Topic 4, Brackets Coloring

Xiao Yijiang got another bunch of parentheses, which are strictly matched. Now color the brackets. There are three requirements for coloring: 1. There are only three coloring schemes, no coloring, red coloring, and blue coloring. 2. Only one of each pair of brackets should be colored. 3. Two adjacent brackets cannot be colored in the same color, but they can be uncolored. Question: How many schemes are there for coloring the brackets? The answer is modulo 1000000007.

This question appeared once in the tenth competition. It can be solved by dynamic programming algorithm.

Guess you like

Origin blog.csdn.net/x1051496412/article/details/129480389