"Qing bei Academy 2018-Brush Problem sprint" Contest 5

Source: Internet
Author: User

? The three were inscribed for a day and a half, and the first one was inscribed for about a day. The question person advised me to write from the back, I do not listen, the result T1 thought + tune a day Qwqwqtask 1: Sequence "problem description"? Defines a "good sequence" as a non-descending sequence of length m, and the elements in the sequence are all positive integers of 1-n. Now we randomly generate a "good sequence" in which each different "good sequence" appears in the same probability, seeking the number of occurrences of the majority in this sequence. "Input"? Input file contains multiple sets of data? Each set of data is read in a row of two integers m, N. "Output"? For each set of test data, the output is a real number that represents the answer, exactly 4 digits after the decimal point. "Input and Output sample"

? 1 5
? 2 9
? 3 3

? 1.0000
? 1.2000
? 2.2000

"Sample Explanation"? x indicates the number of occurrences of the majority in the sequence. When m = 3,n = 3 o'clock possible sequences are:
    • 1 1 1 (x=3) 1 1 2 (x=2) 1 1 3 (x=2)

    • 1 2 2 (x=2) 1 2 3 (x=1) 1 3 3 (x=2)

    • 2 2 2 (x=3) 2 2 3 (x=2) 2 3 3 (x=2)

    • 3 3 3 (x=3)

? So the expectation of X is 2.2. "Data range"? 1≤m≤250,1≤n≤10^9? The total number of data groups per point does not exceed 15 groups. Prompted
    • The difficulty of the topic is irrelevant to the problem order.

    • Please pay attention to the accuracy problem.

The key difficulty is how to build the state. Here we set sum[K] [i] [j] for the majority of the number of [1, K], the sequence length of I, the selection of elements of the sum of the number of J. So set the benefits, see below soon will understand:
    • For the sequence itself, we have such a division:
      • For a particular length of the sequence, we consider discretization it.
        into multiple blocks, each consisting of the same elements, altogether ki[1, m] blocks.
        • Select K in the N elements to fill in these blocks, the results of discretization and the sequence itself is consistent, according to the multiplication principle, the number of C (n,k) can be selected directly with the final answer to the corresponding multiplication.
          • To deal with the answer, we maintain a prefix and: the sum of the total number of sequences in the case of the number of <=k
          • Why maintain the prefix and not alone to ask for a certain one? Because the sum restriction condition is more lenient, easy to deduce and judge.

?

When updating, add the previous two cases:

    • The last selected element is the most recent element

    • The last selected element is not the latest element

Circumstances requiring a heavy sentence:

    • The number of people more than k words.

    • If the same element accumulates here k+1 times, it should be removed.

? So the transfer equation can be obtained:
sum[ k ][ i ][ j ]=sum[ k ][ i - 1 ][ j - 1 ]+sum[ k ][ i - 1 ][ j ]; if( k < i )sum[ k ][ i ][ j ]-=sum[ k ][ i - k - 1 ][ j - 1 ];        
? In order to guarantee the accuracy of the answer, a long double is used here. Calculation of combinatorial number: Here I choose the linear recurrence method. Due to the fact that there are 15 groups of data, we choose to pre-process different length cases, and only a combination number of different optional elements can be used. Complexity: O (n^3)
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <    Algorithm>using namespace Std;int T,m,n;long double c[255],sum[255][255][255],f[255][255][255],g[255];int main () {    Freopen ("Sequence.in", "R", stdin);    Freopen ("Sequence.out", "w", stdout);    C[0]=true;        for (register int k=1;k<=251;++k) {sum[k][0][0]=1; for (register int i=1;i<=251;++i) {for (register int j=1;j<=i;++j) {//i-> sequence length j-> total used                Number of elements k-> the number of//sum stores is the number of numbers that can be constructed in the current situation of majority.                 Because it is a step-by-step recursion, it can be applied directly to all m∈[1,251] situations.                SUM[K][I][J]=SUM[K][I-1][J-1]+SUM[K][I-1][J];                    What is maintained here is a prefix and: the sum of the total number of numbers in the case of K and//update, the previous two cases are accumulated://-> The last selected element is the most recent element                     The last selected element is not the newest element if (k<i) {sum[k][i][j]-=sum[k][i-k-1][j-1];                     Need to weigh the situation: the number of the number of more than K words. Equivalent toIf the same element accumulates here k+1 times, it should be removed.         }}}} while (Cin>>m>>n) {memset (g,0,sizeof (g));        for (register int i=1;i<=m;++i) {c[i]=c[i-1]* (n-i+1)/I; }//O (m) recursive combination number for (register int k=1;k<=m;++k) {for (register int j=1;j<=m;++j) {G[k]            +=SUM[K][M][J]*C[J];         }//count Sum.        } long double ans=0;        G represents the total number of possible types of cases, which are cumulative for (register int k=1;k<=m;++k) {ans+=k* (g[k]-g[k-1])/g[m];    }//give the answer to printf ("%.4lf\n", (double) ans); } return 0;}
? T1 is quite difficult, but T2t3 is a great flood problem. Task 2: Game "problem description"? Little h likes to play games. She will first choose a number?? 0>2 and modify it in every round of the game. In the first round of games, small H selects a prime number p<????? 1, and make???? is a multiple of the minimum p and is greater than or equal to????? 1. Now known?? 2, to find the smallest possible?? 0. "Input"? A line of an integer representation?? 2. "Output"? An integer line represents the answer. "Input Output Sample" IN:20OUT:15 "Data range"
    • 4≤?? 2≤10^6

    • For 100% of data: Guaranteed?? 2 are not prime numbers.

The surface is a bit around, the others are OK. Direct simulation:
    • To H2 decomposition factorization
    • Find the composite H1 (linear sieve pretreatment) within the range of the factorization P2 and H2
    • For each H1 to find its maximum factorization, go straight to the optimal solution (a little bit of optimization complexity O (√n))
    • No, using queue can simplify the code.
#include <queue> #include <cstdio> #include <cstring> #include <iostream> #define MAXN    1000010using namespace Std;int h_2,cnt,ans=maxn,prime[maxn];bool vis[maxn];void get_prime (int n) {vis[1]=true;        for (int i=2;i<=n;++i) {if (!vis[i]) {prime[++cnt]=i;            } for (int j=1;j<=cnt&&i*prime[j]<=n;++j) {vis[i*prime[j]]=true;        if (i%prime[j]==0) break;    }}}int Main () {freopen ("game.in", "R", stdin);    Freopen ("Game.out", "w", stdout);    scanf ("%d", &h_2);    Get_prime (h_2);    Get Prime List queue<int>prime2;    int tmp_h2=h_2;        for (int i=1;i<=cnt;++i) {if (tmp_h2==1) break;            if (tmp_h2%prime[i]==0) {while (tmp_h2%prime[i]==0) {tmp_h2/=prime[i];        } prime2.push (Prime[i]);    }} queue<int>hh1; while (!        Prime2.empty ()) {int Tmp=prime2.front ();        Prime2.pop (); for (int i=h_2-tmp+1;i<=h_2;++i) {if (Vis[i]) {Hh1.push (i); }}} while (!        Hh1.empty ()) {int Tmp=hh1.front ();        Hh1.pop ();        int tt=tmp;            for (int i=1;i<=cnt;++i) {while (tt%prime[i]==0) {tt/=prime[i];                } if (tt==1) {//tt is finished ans=min (ans,tmp-prime[i]+1);            Break                } if (!vis[tt]) {//tt is already a prime ans=min (ans,tmp-tt+1);            Break    }}} printf ("%d", ans); return 0;}
Task 3: Checkerboard "problem description"? small h and Little C play chess on a n*m black and white board. They took turns to operate. Small h Initiator. Each time you can choose a black lattice, with this grid for the lower right corner, the upper left corner of the chessboard is the upper left corner, the matrix of all the grid color from black to white, from white to black. I can't find a man with a black lattice to lose. Unusually, because small H and small c are good friends, Little H wants to make it as small C as possible to win. and small c is a competitive person, he wants to win as much as possible. Then on this basis, small H initiator, who can win it. "Input"? The first line is an integer t, which indicates that there is a T group of data. The first row of each group of data is two integers n, m, indicating the size of the chessboard. The next n lines each row of M characters B (black) or w (white) represent the color of each lattice. "Output"? For each query for each group, output one line, "H" or "C" (without quotation marks). means that he will win. "Input and Output sample"

Chess.in:
? 3 2 2
? Bw
? Ww
? 2 2
? Ww
? Ww
? 2 2
? WB
? Bw
Chess.out:

? H
? C
? C

"Data Range"
    • 1≤n,m≤100

    • For 100% of data: 1≤t≤100.

? The concluding question.
    • Little h He will not win if he doesn't want to win (never pick a winning situation every time)
    • But there is a situation where little C will never win the state:
      • For a pawn in the upper-left corner, it will be selected every time.
      • If it is B, then no matter how many times the small C can not control it, because small C can not end the game.
? As long as the small C absolutely can't win that is small H win.
#include<cstdio>#include<cstring>char ch[110][110];int main(){    freopen("chess.in","r",stdin);    freopen("chess.out","w",stdout);    int T,n,m;    scanf("%d",&T);    while(T--){//      memset(ch,0,sizeof(ch));        scanf("%d%d",&n,&m);        for(register int i=1;i<=n;++i){            for(register int j=1;j<=m;++j){                do{                    ch[i][j]=getchar();                }while(ch[i][j]==‘ ‘||ch[i][j]==‘\n‘);                            }        }         if(ch[1][1]==‘B‘){            puts("H");        }else{            puts("C");        }    }    return 0;}

"Qing bei Academy 2018-Brush Problem sprint" Contest 5

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.