Codeforces Round #105 (Div. 2) ABCDE

Source: Internet
Author: User

A. Insomnia Cure

Ah can only speak English is too poor, one eye question I watched for three minutes.

Test instructions: Give 5 numbers k, l, m, n and D, 1~d can be k, l, m< /c10>, n the number of at least one divisible.

A: ...

Code:

#include <iostream>using namespacestd;intMain () {intA, B, C, D, N; CIN>> a >> b >> c >> D >>N; intAns =0;  for(inti =1; I <= N; ++i)if(i% a && i% b && I% c && I% d) + +ans; cout<< N-ans; return 0;}

B. Escape

Test instructions: or 5 numbers , vP, vd, T, F and C, Princess Speed is VP, the speed of the Dragon is VD, the princess first run time t, the Dragon began chasing the princess, chasing, the Princess threw a treasure, the dragon picked up back to the beginning and then took the time F to hide the treasure, ask at least how many treasures princess to run distance c.

Puzzle: Analog bar, there is a trick bar, that is, if the VP>=VD direct output 0.

Code:

#include <iostream>using namespacestd;intMain () {intVP, VD, T, F, C; CIN>> VP >> VD >> T >> F >>C; DoubleA = VP *T; DoubleD = VD-VP; intAns =0; DoubleT1 = A/D; A+ = T1 *VP; if(VP >= VD) {cout <<'0';return 0; }  while(A <c) {ans++; A+ = VP * (f + A/VD); T1= A/D; A+ = T1 *VP; } cout<<ans; return 0;}

C. Terse Princess

Test instructions: Silly forced princess Choose husband, n candidates, each has a wealth value, when see a person than before all the people are rich, the princess shouted "Oh", when see a person's wealth than in front of all the wealth and more, the princess shouted "Wow" (at this time do not shout "Oh"), a total of n people, shout a "Oh" and B-Times "Wow" allows you to construct a wealth value sequence that is not built out on the output-1.

The puzzle: Probably think about to know, first a 1, then B "Wow", then a "Oh", and then all 1. There is a trick, if b=0, then the constructed array is 1 2 ... , 2 is going to be "Wow". (Div2 c I will not do, weak not ...)

Code (write a diff):

#include <iostream>#include<cstdio>using namespacestd;intMain () {intA, b, N; CIN>> N >> a >>b; inti =0; intans[ $]; ans[0] =1; if(b) { for(i =1; I <= b; ++i) {ans[i]= ans[i-1] *2; if(Ans[i] >50000) {printf ("-1"); return 0; }        }         for(; I <= b+a; + +)i) {ans[i]= ans[i-1] +1; }         for(; i < n; + +)i) {ans[i]=1; }    } Else {        if(A && a >= n1) {printf ("-1"); return 0; } ans[1] =1;  for(i =2; I <= A +1; ++i) {ans[i]= ans[i-1] +1; }         for(; i < n; ++i) Ans[i] =1; } printf ("%d", ans[0]);  for(inti =1; I < n; ++i) printf ("%d", Ans[i]); return 0;}

D. Bag Of Mice

Test instructions: Or a silly princess, Helong play games. There is a pocket, there are w white mice and b black mice, two people take turns to catch the mouse, the first to catch microscope win, the Dragon will scare off a mouse after a time, scare away the mouse is not caught. Princess first Catch, if no one caught microscope is dragon win. The probability of seeking a princess to win.

The more simple probability DP. Positive push from the initial state.

Code:

#include <iostream>#include<cstdio>using namespacestd;Const intN =1005;Doubledp[n][n][2];intMain () {intA, B; CIN>> a >>b; dp[a][b][1] =1;  for(inti = A; I >=0; --i) { for(intj = b; J >=0; --j) {if(j) dp[i][j-1][2] + = dp[i][j][1] * J/(i+j); if(J >1) dp[i][j-2][1] + = dp[i][j][2] * J/(I+J) * (J-1)/(i+j-1); if(i && J) dp[i-1][j-1][1] + = dp[i][j][2] * J/(I+J) * I/(i+j-1); }    }    DoubleAns =0;  for(inti = A; I >=0; --i) for(intj = b; J >=0; --j)if(i) ans + = dp[i][j][1] * I/(i+j); printf ("%.9f", ans); return 0;}

E. Porcelain

Test instructions: N shelves, there are some porcelain on each shelf, for each shelf can only take one from the side (left or right), ask M times to fetch the total value of porcelain.

Puzzle: Similar to 01 backpack. Preprocess each shelf with 1~c (assuming that the shelf has a total of C porcelain) The maximum value of a porcelain. Each shelf can only be selected once. Look at the code specifically.

Code:

#include <iostream>#include<cstdio>using namespacestd;Const intN = the;intA[n], c[n];intV[n][n];intdp[10005];intL[n], r[n];intMain () {intN, M; CIN>> N >>m;  for(inti =1; I <= N; ++i) {cin>>C[i];  for(intj =1; J <= C[i]; ++J) Cin >>A[j];  for(intj =1; J <= C[i]; ++j) {L[j]= l[j-1] +A[j]; R[J]= r[j-1] + a[c[i]-j+1]; }         for(intj =1; J <= C[i]; ++j) for(intK =0; K <= J; ++k) V[i][j]= Max (V[i][j], l[k] + r[j-K]); }     for(inti =1; I <= N; ++i) for(intj = m; J >=0; --j) for(intK =0; K <= C[i] && k <= J; ++k) Dp[j]= Max (Dp[j], dp[j-k] +V[i][k]); cout<<Dp[m]; return 0;}

Codeforces Round #105 (Div. 2) ABCDE

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.