Sorting out the wrong questions in the preliminary competition of Xinao

Posted by lostsoul111455 on Wed, 22 Dec 2021 09:33:40 +0100

1.

 2.

 3.

4. 

5. 

6.7. 

8.

 

9. Problem solving

Each test paper has an 88 # digit binary serial number. It is valid only if and only if a serial number contains an even number of ^ 11 ^. For example, 0000000000000000000000, 0101001101010011 are valid serial numbers, but 1111111011110 is not. Then, valid serial numbers are shared____ One.

/2 because there are eight test entry numbers in total, each of which can be 0 and 1, odd or even, so it is 256 / 2 = 128

10.

The basic operations of defining a string are: deleting a character, inserting a character, and modifying a character to another character. The minimum number of operation steps to change the string {AA} into the string {BB}, which is called the editing distance from the string {AA} to the string {BB}. The editing distance from the string "ABCDEFG" to the string "BADECG" is _.

Delete 'A' from the first string, change 'C' to 'A', and change 'F' to 'C' to become the second string. The editing distance is {3.

 

#include <iostream>
#include <string>
using namespace std;
int main(){
    string map = "22233344455566677778889999";
    string tel;
    int i;
    cin>>tel;
    for (i = 0; i < tel.length(); i++)
        if ((tel[i] >= '0') && (tel[i] <= '9'))
            cout<<tel[i];
        else if ((tel[i] >= 'A') && (tel[i] <= 'Z'))
            cout<<map[tel[i] - 'A'];
    cout<<endl;
    return 0;
}

The string of map has a total of 26 bits, corresponding to 26 letters. In the input example of CCF-NOIP-2011, if - is removed, it is c, and the corresponding 2 is 22366472011

10.

#include <iostream>
#include <cstring>
using namespace std;
const int SIZE = 100;
int main(){
    int n, i, sum, x, a[SIZE];
    cin>>n;
    memset(a, 0, sizeof(a));
    for (i = 1; i <= n; i++) {
        cin>>x;
        a[x]++;
    }
    i = 0; sum = 0;
    while (sum < (n / 2 + 1)) {
        i++;
        sum += a[i];
    }
    cout<<i<<endl;
    return 0;
}
for (i = 1; i <= n; i++) {
        cin>>x;
        a[x]++;
    }

The sum below is to count the number of occurrences of a number, so it is 3

11.

#include <iostream>
using namespace std;
const int SIZE = 50;
int n1, m1, n2, m2, a[SIZE][SIZE], b[SIZE][SIZE];
int main(){
    int i, j, k1, k2;
    bool good, haveAns;
    cin>>n1>>m1;
    for (i = 1; i <= n1; i++)
        for (j = 1; j <= m1; j++)
            cin>>a[i][j];
    cin>>n2>>m2;
    for (i = 1; i <= n2; i++)
        for (j = 1; j <= m2; j++)
            ①;
    haveAns = false;
    for (i = 1; i <= n1 - n2 + 1; i++)
        for (j = 1; j <= ②; j++){
            ③;
            for (k1 = 1; k1 <= n2; k1++)
                for(k2 = 1; k2 <= ④; k2++)  {
                    if (a[i + k1 - 1][j + k2 - 1] != b[k1][k2])
                        good = false;
                }

            if (good) {
                cout<<i<<' '<<j<<endl;
                ⑤;
            }
    }
    if (!haveAns)
        cout<<"There is no answer"<<endl;
    return 0;
}

1. It is inserted above, so it is also inserted below;

2. Because the above is the update row, the following is the column,

3. Update the status of good, n2 above and m2 below

5. Update haveans when you find the answer;

12.

#include <iostream>
using namespace std;
int solve(int n, int m){Preferences
    int i, sum;
    if (m == 1) return 1;
    sum = 0;
    for (i = 1; i < n; i++)
        sum += solve(i, m - 1);
    return sum;
}
int main(){
    int n, m;
    cin>>n>>m;
    cout<<solve(n, m)<<endl;
    return 0;
}

This problem is recursive and can be calculated in tables. When n=7 and m=4, it is 20

13.

#include <iostream>
#include <string>
using namespace std;
const int SIZE = 200;
struct hugeint {
  int len, num[SIZE];
};
//Where len represents the number of bits of a large integer; num[1] represents one bit, num[2] represents ten bits, and so on
hugeint times(hugeint a, hugeint b) {
    //Calculates the product of large integers a and b
    int i, j; hugeint ans;
    memset(ans.num, 0, sizeof(ans.num));
    for (i = 1; i <= a.len; i++)
        for (j = 1; j <= b.len; j++)
            ①+= a.num[i] * b.num[j];
    for (i = 1; i <= a.len + b.len; i++) {
        ans.num[i + 1] += ans.num[i] / 10;
        ②;
    }
    if (ans.num[a.len + b.len] > 0)
        ans.len = a.len + b.len;
    else
        ans.len = a.len + b.len - 1;
    return ans;
}
hugeint add(hugeint a, hugeint b){
    //Calculate the sum of large integers a and b
    int i; hugeint ans;
    memset(ans.num, 0, sizeof(ans.num));
    if (a.len > b.len)
        ans.len = a.len;
    else
        ans.len = b.len;
    for (i = 1; i <= ans.len; i++) {
        ans.num[i] +=③;
        ans.num[i + 1] += ans.num[i] / 10;
        ans.num[i] %= 10;
    }
    if (ans.num[ans.len + 1] > 0) ans.len++;
    return ans;
}
hugeint average(hugeint a, hugeint b){
    //Calculates the integer part of the average of large integers a and b
    int i; hugeint ans;
    ans= add(a, b);
    for(i = ans.len; i >= 2; i--) {
        ans.num[i  - 1] += (④) * 10;
        ans.num[i] /= 2;
    }
    ans.num[1] /= 2;
    if (ans.num[ans.len] == 0) ans.len--;
    return ans;
}
hugeint plustwo(hugeint a) {
    //Calculates the result of a large integer a plus 2
    int i; hugeint ans;
    ans = a;
    ans.num[1] += 2;
    i = 1;
    While ((i <= ans.len) && (ans.num[i] >= 10)) {
        ans.num[i + 1] += ans.num[i] / 10;
        ans.num[i] %= 10;
        i++;
    }
    if (ans.num[ans.len + 1] > 0)⑤;
    return ans;
}
bool over(hugeint a, hugeint b){
//If the large integer a > b, it returns true; otherwise, it returns false
    int i;
    if (⑥) return false;
    if (a.len > b.len) return true;
    for (i = a.len; i >= 1; i--) {
        if (a.num[i] < b.num[i])return false;
        if (a.num[i] > b.num[i]) return true;
    }
    return false;
}
int main(){
    string s;
    int i;
    hugeint target, left, middle, right;
    cin>>s;
    memset(target.num, 0, sizeof(target.num));
    target.len = s.length();
    for (i = 1; i <= target.len; i++)
        target.num[i]= s[target.len  - i] - ⑦;
    memset(left.num, 0, sizeof(left.num));
    left.len = 1;
    left.num[1] = 1;
    right = target;
    do {
        middle = average(left, right);
        if (over(⑧))right = middle;
        else left = middle;
    } while (!over(plustwo(left), right));
    for (i = left.len; i >= 1; i--)
        cout<<left.num[i];
    cout<<endl;
    return 0;
}

Dichotomy + high precision

add is a+b, so the first two blanks can get if in 5 is right ans. Len's modified times is the multiplication. Over 'is if a "B" returns true, plustwo is the result of a+2, a two-point, and average is an average. If a.len > b.len, it means that a is larger than B. over is a function of size. If a > b is true, a < B is false. Finally, contact the context and get that here is times(middle,middle),target, so compare the square sum of middle and target.