CF 301 Div2

Source: Internet
Author: User

A-combination Lock

The main topic: To have N (0-9) ring password lock, a few strings s1->s2 the minimum number of moves;

Topic Analysis:

Simple simulation;

Code:

const int N=100007;char s1[n],s2[n];int Main () {    int N;    while (scanf ("%d", &n) ==1)    {        int ans=0;        scanf ("%s%s", s1+1,s2+1);        for (int i=1;i<=n;i++)        {            int a=s1[i]-' 0 ';            int b=s2[i]-' 0 ';            if (a>b) swap (A, b);            Ans+=min (b-a,a+ (9-b) +1);        }        printf ("%d\n", ans);    }    return 0;}



B-school Marks

The main topic: N number, known as K, the median >=y; and all the number sum<=x; fill the remaining n-k number;

Topic Analysis:

Because sum is less than X, try to fill in decimals. Mid left Fill 1, right fill y;

Code:

vector<int> Ans;int Main () {int n,k,p,x,y;        while (scanf ("%d%d%d%d%d", &n,&k,&p,&x,&y) ==5) {ans.clear ();        int sum=0;        int mi=0;        int flag=0;            for (int i=0;i<k;i++) {int v;cin>>v;            if (v>=y) flag++;            if (v<y) mi++;        Sum+=v; } if (mi>n/2| |            sum>x) {printf (" -1\n");        Continue            } while (n/2+1-(K-MI) <0&&flag>1) {mi++;        flag--;            } for (int i=0;i<n/2-mi;i++) {ans.push_back (1);        Sum+=1;            } for (int i=0;i<n/2+1-(K-MI); i++) {ans.push_back (y);            Sum+=y;        flag=1; } if (sum<=x&&flag&& (signed int) ans.size () +k==n) {for (int i=0;i< (signed int) Ans.siz                E (); i++) {if (!i) printf ("%d", ans[i]);   else printf ("%d", ans[i]);         } printf ("\ n");        } else{printf (" -1\n"); }} return 0;}

C-ice Cave

The main idea: to the maze, X can not go, '. ' Walk two times, from (R1,C2)---> (r2,c2) request (R2,C2) walk two times;

Topic Analysis:

DFS,CNT records the number of times, (well, I was using the also mark, ' * ' means have gone over);

Code:

const int N=100007;char gra[555][555];int go[4][2]={{0,1},{0,-1},{-1,0},{1,0}};int r1,c1,r2,c2;int ok;int n,m;void Dfs (int cx,int cy)    {int x, y;    if (OK) return;        for (int i=0;i<4;i++) {x=cx+go[i][0];        Y=CY+GO[I][1]; if (1<=x&&x<=n&&1<=y&&y<=m) {if (gra[x][y]!= ' x ') {if (g                ra[x][y]== ' * ') {if (X==R2&AMP;&AMP;Y==C2) ok=1;                    } else{gra[x][y]= ' * ';                    DFS (x, y);                Gra[x][y]= '. ';        }}}}}int main () {while (scanf ("%d%d", &n,&m) ==2) {ok=0;        for (int i=1;i<=n;i++) scanf ("%s", &gra[i][1]);        scanf ("%d%d%d%d", &AMP;R1,&AMP;C1,&AMP;R2,&AMP;C2);        if (gra[r2][c2]== ' X ') gra[r2][c2]= ' * ';        DFS (R1,C1);        if (OK) printf ("yes\n");    else printf ("no\n"); } return 0;} /*4 6X... Xx... Xx.. X.. X...... X1 64 6*/


D-bad Luck Island

Main topic: Initial 3 species: R stone, s scissors, p cloth; the probability of any pair meeting is equal (regardless of the same kind of meeting); The probability of leaving only one species at the end;

Topic Analysis:

Probability knowledge, if present (stone, scissors, cloth): (i,j,k); then the probability is dp[I [j] [K] * (i * k + i * j + J * k) if the next step is to hang the stone (i-1,j,k));

others;

Code:

const int n=100007;double dp[110][110][110];int Main () {int r,s,p;                while (scanf ("%d%d%d", &r,&s,&p) ==3) {for (int. i=0;i<=r;i++) {for (int j=0;j<=s;j++) {                for (int k=0;k<=p;k++) {dp[i][j][k]=0.0;        }}} dp[r][s][p]=1.0;                    for (int i=r;i>=0;i--) {for (int. j=s;j>=0;j--) {for (int k=p;k>=0;k--) {                    if ((i==0&&j==0&&k==0)) continue; if (((i+1) *k+j*k+ (i+1) *j)//guarantee that this transfer can be established, the denominator is not 0; >0 (dp[i][j][k]+=1.0* (dp[i+1][j][k]*) i+1)/((*k) *                    k+j*k+ (i+1) *j);                    if (((j+1) *i+i*k+ (j+1) *k) >0 (dp[i][j][k]+=1.0* (dp[i][j+1][k]*) j+1)/((*i) j+1 (*i+i*k+) j+1); if ((i*j+i* (k+1) +j* (k+1) >0) dp[i][j][k]+=1.0* (dp[i][j][k+1]* (k+1) *j)/(i*j+i* (k+1                    ) +j* (k+1)); Cout<<dp[i][j][k]<<endL        }}} double a=0.0,b=0.0,c=0.0;        for (int i=1;i<=r;i++) a+=dp[i][0][0];        for (int j=1;j<=s;j++) b+=dp[0][j][0];        for (int k=1;k<=p;k++) c+=dp[0][0][k];    printf ("%.12f%.12f%.12f\n", a,b,c); } return 0;}


Cf!!!!!!!! When to div1!!!


CF 301 Div2

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.