2017 Group Program Design ladder race-Grand area match __ Simulation

Source: Internet
Author: User
Tags diff

Today for the group competition, had to give up personal netease written test ...

3h only AC l1-1 ~ l1-8, l2-1, l2-3 ~ l2-4, l3-1 (all AC after the game)

L2-2 (AC) and l3-3 (AC) each had 22 points, L2-2 first wanted to use the list to simulate, but feel too troublesome, instead of array simulation, very good to write, but hang the second test point; l3-3 timeout at a test point with Dfs Dfs, see space, think of a map map pruning, Finally did not finish (after the return to add a variety of pruning or timeout ...) The end result is that the misuse of map and set causes timeouts, and pruning is not a problem.

L3-2 (already AC) request is very complex, feel a little trouble to give up, make up when only found in fact is also very simple.

Competition website

L1-1 the address of the problem . Year of birth

Topic link

The above is a wonderful piece of Sina Weibo: "I was born in 1988, until I was 25 years old and I met 4 different years." In other words, it was not until 2013 that the "4 numbers were different" requirements. Please, according to the requirements, automatically fill "I was born in y years, until the age of X to meet n numbers are not the same year" this sentence.
Input Format
Enter the number n of the different numbers in the year of birth y and the target year in the row, where y is between [1, 3000], and n can be 2, or 3, or 4. Note that less than 4-digit years are to be preceded by 0, for example A.D. 1 is considered 01, there are 2 different numbers 0 and 1.
output Format
According to the input, the output X and the year to reach the required. The numbers are separated by 1 spaces, and there must be no extra spaces between the lines. Year to 4-bit output. Note: The so-called "n numbers are not the same" means that different numbers are exactly n. If "2013" is considered to satisfy the "4 digits are different" conditions, but not considered to meet the 2-bit or 3-digit different conditions.
Input Sample 1
1988 4
Output Sample 1
25 2013
Input Sample 2
1 2
Output Sample 2
0 0001 Ideas-enumeration

The data range and answer range are small, so you can enumerate the judgments directly. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int cnt;
BOOL Vis[11];

int calc (int y) {
    memset (Vis, false, sizeof (VIS));
    CNT = 0;
    for (int i = 0; i < 4; ++i) {//because you want to count all four digits, you should include each of the
        if (!vis[y%)) {
            ++cnt;
            Vis[y%] = true;
        }
        y/=;
    }
    return cnt;
}

int y, k;

int main () {
    while (2 = = scanf ("%d%d", &y, &k)) {for
        (int i = y;; ++i) {
            if (calc (i) = k) {
                PR intf ("%d%04d\n", i-y, i);
                break;
            }
    }} return 0;
}
l1-2. Dot Praise

Topic link

There is a "point of praise" feature on Weibo, and you can support your favorite blog post with a compliment. Each blog post has a number of tags depicting its characteristics, and the type of blog you are praising also indirectly depicts your character. The subject requires you to write a program to analyze this person's characteristics by counting a person's record of praise.
Input Format
The input gives a positive integer n (<=1000) in the first row and is the number of posts that the user points to. Then n rows, each row gives a description of the character of the post that it points to, in the form of "K F1 ..." FK ", where 1<=k<=10,fi (I=1, ..., K) is the attribute tag number, we will have all the feature labels numbered from 1 to 1000. Numbers are separated by spaces.
output Format
Statistics the most common feature tag in all of the posts that are being hailed, outputting its number and occurrences in one line, with a number of 1 spaces. If there is a tie, the output number is the largest.
Input Sample
4
3 889 233 2
5 100 3 233 2 73
4 3 73 889 2
2 233 123
Output Sample
233 3 Ideas-simulation

Counts the number of occurrences of each attribute label, and then outputs the largest number that appears most frequently. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n, k, num, cnt[1003], MX;

int main () {
    while (1 = = scanf ("%d", &n)) {
        mx = 0;
        memset (CNT, 0, sizeof (CNT));
        while (n--> 0) {
            scanf ("%d", &k);
            while (k--> 0) {
                scanf ("%d", &num);
                mx = max (mx, ++cnt[num]);
            }
        for (int i = 1000 i >= 0;-i) {
            if (cnt[i] = = mx) {
                printf ("%d%d\n", I, Cnt[i]);
                break;
            }
    }} return 0;
}
l1-3. Valentine's Day

Topic link

Above is the friend Circle of a wonderful flower stickers: "February 14 Valentine's Day, I decided to benefit everyone." 2nd Zane The 14th one, I'll introduce you both to ..... I have three meals ... You two please ... ". Here is a list of friends to put down a little praise, please find out the two to treat the unlucky eggs.
Input Format
Enter the name of the person who does not know how many points in the order of praise, each of whom has one row, a non-empty word that is no more than 10 English letters, ends with a carriage return. An English period "." The sign input end, this symbol is not counted in the point praise list.
output Format
Outputs the conclusion on one line according to the point of praise: if there is a 2nd person A and 14th person B, then the output "A and B are inviting you to dinner ..."; if only a has no B, then output "A is T He is just one for you ... "If you don't have a, you will output" Momo ... No one is for you ... ".
Input Sample 1
Gaoxzh
Magi
Einst
Quark
Laolao
fatmouse
Zhashen
Fantac Y
latesum
Sensen
Quanquan
Whatever
whenever
Potaty
hahaha
.
Output Sample 1
Magi and Potaty are inviting to dinner ...
Enter sample 2
Laolao
Fatmouse
Whoever
.
Output Sample 2
Fatmouse is the ' only one ' for your ...
Enter sample 3
Laolao
.
Output Sample 3
Momo ... No one is for you ... Ideas-Impersonation

Find out who (2\) individual and 14\ (if any), and then according to the total number of output corresponding content. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int cnt;
Char a[11], b[11], s[11];

int main () {
    cnt = 0;
    while (true) {
        scanf ('%s ', s);
        if (s[0] = = '. ') {Break
            ;
        }
        ++cnt;
        if (cnt = = 2) {
            memcpy (a, S, sizeof (a));
        }
        if (cnt = =) {
            memcpy (b, S, sizeof (b));
        }
    ;
    if (CNT >=) {
        printf ("%s and%s are inviting to dinner...\n", A, b);
    }
    else if (CNT >= 2) {
        printf ('%s is ' only one for you...\n ", a);
    }
    else {
        printf ("Momo ..."). No one is for you ... \ n ");
    return 0;
}
l1-4. A Times B

Topic link

Look, I'm not lying to you--this is a question you can finish in 10 seconds: given two integers A and B with an absolute value of no more than 100, output a Times B.
Input Format
The input gives two integers a and B ( -100 <= A, B, <= 100) in the first row, separated by a space between the digits.
output Format
Output the value of a Times B on a single line.
Input Sample
-8 13
Output Sample
-104 Ideas-simulation

Output the value of A∗b a*b according to the instructions. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a, B;

int main () {
    while (2 = = scanf ("%d%d", &a, &b)) {
        printf ("%d\n", A * b);
    }
    return 0;
}
l1-5. A Times B

Topic link

It's really a simple question--given two integers a and B that are not more than 100 in absolute value, you are required to output the results in the format of the "a/b= quotient."
Input Format :
The input gives two integers a and B ( -100 <= A, B, <= 100) in the first row, separated by a space between the digits.
output Format :
Output in one line: if the denominator is a positive number, output "a/b= quotient"; If the denominator is negative, enclose the denominator in parentheses to output; If the denominator is zero, the output should be "Error". The output quotient should retain 2 digits after the decimal point.
Input Sample 1
-1 2
Output Sample 1
-1/2=-0.50
Input Sample 2
1-3
Output Sample 2
1/(-3) =-0.33
Input Sample 3
5 0
Output Sample 3
5/0=error Ideas-simulation

The denominator and the result of the expression are processed accordingly according to the denominator's plus and minus zeros. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a, B;

int main () {while
    (2 = = scanf ("%d%d", &a, &b)) {
        if (b < 0) {
            printf ("%d/(%d) =%.2lf\n", A, B, 1.0 * A/b);
        }
        else if (b > 0) {
            printf ("%d/%d=%.2lf\n", A, B, 1.0 * b);
        }
        else {
            printf ("%d/%d=error\n", A, b);
        }
    }
    return 0;
}
l1-6. New World

Topic link

There is no input to this super simple topic.
All you have to do is output the programmer's famous "Hello World" in the first line, and the "Hello New World" in the second line. train of thought-simulation

In accordance with the output can be. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main () {
    printf ("Hello World\nhello New world\n");
    return 0;
}
l1-7. Antique Typesetting

Topic link

Chinese ancient writing, from right to left vertical typesetting. I ask you to write a program, a paragraph of text according to the antique layout.
Input Format
The input gives a positive integer n (<100) in the first row and is the number of characters per column. The second line gives a non-empty string with a length of not more than 1000, ending with a carriage return.
output Format
Format the given string in the antique form, n characters per column (except that the last column may be less than N)
Input Sample
4
This is a test case
Output Sample
ASA T
St IH
E TSI
Ce s train of thought-simulation

The topic given the number of lines, according to the length of the string can calculate the number of rows, from the first character according to the rules fill in, the last enough space to complete, and then output by line. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int row, col, R, C, Len;
Char s[1003], res[103][1003];

int main () {
    while (1 = = scanf ("%d", &row))
        {gets (s);
        Len = strlen (s);
        Col = len/row + (len% row = = 0? 0:1);
        for (int i = 0; i < row; ++i) {
            res[i][0] = ';
            Res[i][col] = ' I ';
        }
        R = 0;
        c = col-1;
        for (int i = 0; i < len; ++i) {
            res[r][c] = s[i];
            ++r;
            if (r = = row) {
                --c;
                R = 0;
            }
        }
        for (int i = 0; i < row; ++i) {
            printf ("%s\n", Res[i]);
        }
    return 0;
}
L1-8, the best couple is inferior in height

Topic link

Experts through a number of couples study data found that the best couple height difference follows a formula: (The woman's height) x1.09= (male height). If it fits, your height difference, whether it's holding hands, hugging, kissing, is the most harmonious difference.
Please write a program to calculate the best height of his/her couple for any user.
Input Format
Enter the first row to give the positive integer n (<=10), the number of users to come to query. Then n rows, each line according to "sex height" in the format given to the user to query the gender and height, where "gender" as "F" for Women, "M" for Men, "height" is the interval [1.0, 3.0] between the real number.
output Format
For each query, calculate the optimal height of the couple for the user on a single line, reserving 2 digits after the decimal point.
Input Sample
2
M 1.75
F 1.8
Output Sample
1.61
1.96 Ideas-simulation

According to the formula can be:
If male, height divided by 1.09 height divided by 1.09
If it's a female, multiply the height by 1.09 times the 1.09 code .

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n;
Double h;
Char s[3];

int main () {while
    (1 = scanf ("%d", &n)) {while
        (n--> 0) {
            scanf ("%s%lf", S, &h);
            printf ("%.2lf\n", s[0] = = ' M '? H/1.09:h * 1.09)
        ;
    }
    return 0;
}
l2-1 of the flock.

Topic link

In social networks, we define an "activity" for everyone, and we want to divide the population into two broad categories, namely, extroversion (outgoing, high activity) and inward-looking (introverted, i.e., low activity). The two groups are required to be as close as possible, and their total activity gap is as wide as possible.
Input Format :
Enter the first row to give a positive integer n (2 <= n <= 105). The next row gives n positive integers, each of which is a space-separated activity. The title guarantees that these figures and their numbers will not exceed 231.
output Format :
Output in the following format

Outgoing #: N1
Introverted #: N2
Diff = N3
Among them, N1 is the number of outward-looking people, N2 is the number of introverts, N3 is the absolute value of the difference of total activity of two groups of people.
Input Sample 1
10
23 8 10 99 46 2333 46 1 666 555
Output Sample 1
Outgoing #: 5
Introverted #: 5
Diff = 3611
Input Sample 2
13
110 79 218 69 3721 100 29 135 2 6 13 5188-85
Output Sample 2
Outgoing #: 7
Introverted #: 6
Diff = 9359 train of thought-analog

The topic given the number of lines, according to the length of the string can calculate the number of rows, from the first character according to the rules fill in, the last enough space to complete, and then output by line. Code

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n, num[100003], sum, outgoing;

int main () {
    while (1 = scanf ("%d", &n)) {
        sum = outgoing = 0;
        for (int i = 0; i < n; ++i) {
            scanf ("%d", num + i);
            Sum + + num[i];
        }
        Sort (num, num + N);
        for (int i = n >> 1; i < n; ++i) {
            outgoing + = Num[i];
        }
        printf ("Outgoing #:%d\n", (n + 1) >> 1);
        printf ("Introverted #:%d\n", n >> 1);
        printf ("Diff =%d\n", (outgoing << 1)-sum);
    }
    return 0;
}
l2-2-Polynomial a divided by B

Topic link

This is still a question about a/b, except that A and B. have been replaced with polynomials. You need to compute the quotient Q and R of the two polynomial division, where the order of R must be less than the order of B.
Input Format
The input is divided into two lines, each row gives a non-0 polynomial, first gives a, and then gives B. Each line is formatted as follows:
N e[1] c[1] ... e[n] c[n]

where n is the number of the polynomial not 0, e[i] is the exponent of the I non 0 item, and C[i] is the coefficient of the first non 0. The items are given in an exponential descending order to ensure that all indices are distinct nonnegative integers, all coefficients are not 0 integers, all integers are within the integer range.
output Format
Two lines successively output quotient and remainder, output format and input format is the same, the output coefficient retains 1 digits after the decimal point. The number of peers is separated by 1 spaces with no extra space between the end of the line. Note: The 0 polynomial is a special polynomial, corresponding to the output of "0 0 0.0". However, a non-0 polynomial cannot output 0 coefficients, including items rounded to 0.0. In the sample, the remainder polynomial actually has a constant term " -1/27", but is not output because it is rounded to 0.0.
Input Sample
4 4 1 2-3 1-1 0-1
3 2 3 1-2 0 1
Output Sample
3 2 0.3 1 0.2 0-1.0
1 1-3.1 train of thought-simulation

The game was intended to use a linked list simulation, write a little feel too troublesome, instead of array simulation.

The array subscript represents the exponent, the value represents the coefficient, and then the polynomial division is simulated.
The item of the highest exponent of a is eliminated at a time, until the order of a is less than the order of B or a is 0 polynomial (the problem data is not both A and B are constant polynomials).
I forgot about the game. The highest exponent of the remaining polynomial after each elimination is less than the polynomial Q of each time multiplied, resulting in WA WA in the first

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.