2013 Chengdu Invitational competition solution report

Source: Internet
Author: User
Tags cmath

Before the Shanghai Invitational competition, we warmed up from the 2013 Chengdu Invitational competition. The results of the competition were far beyond our expectation... A few questions may be updated.

Question:

Address: HDU 4716

Question .. I typed this question .. It's troublesome... Sad... Don't you see it...

Code:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main(){    char s[20][20];    int t, x;    int i, j, num=0;    scanf("%d",&t);    while(t--)    {        num++;        scanf("%d",&x);        printf("Case #%d:\n",num);        x=x/10;        s[0][0]='*';        s[0][13]='*';        s[11][0]='*';        s[11][13]='*';        for(i=1;i<13;i++)        {            s[0][i]='-';            s[11][i]='-';        }        for(i=1;i<11;i++)        {            s[i][0]='|';            s[i][13]='|';        }        for(i=1;i<=10-x;i++)        {            for(j=1;j<=12;j++)            {                s[i][j]='.';            }        }        for(i=10-x+1;i<=10;i++)        {            for(j=1;j<=12;j++)            {                s[i][j]='-';            }        }        for(i=0;i<=11;i++)        {            for(j=0;j<=13;j++)            {                printf("%c",s[i][j]);            }            printf("\n");        }    }    return 0;}

E:

Address: hdu4720

Not me... I don't want to do the calculation of geometric questions .... Teammates say it is a template question.

The Code is as follows:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;struct Point{    double x;    double y;} pt[1005];struct Circle{    struct Point center;    double r;};struct Traingle{    struct Point p[3];};double Dis(struct Point p,struct Point q){    double dx=p.x-q.x;    double dy=p.y-q.y;    return sqrt(dx*dx+dy*dy);}double Area(struct Traingle ct){    return fabs((ct.p[1].x-ct.p[0].x)*(ct.p[2].y-ct.p[0].y)-(ct.p[2].x-ct.p[0].x)*(ct.p[1].y-ct.p[0].y))/2.0;}struct Circle CircumCircle(struct Traingle t){    struct Circle tmp;    double a,b,c,c1,c2;    double xA,yA,xB,yB,xC,yC;    a=Dis(t.p[0],t.p[1]);    b=Dis(t.p[1],t.p[2]);    c=Dis(t.p[2],t.p[0]);    tmp.r=(a*b*c)/(Area(t)*4.0);    xA=t.p[0].x;    yA=t.p[0].y;    xB=t.p[1].x;    yB=t.p[1].y;    xC=t.p[2].x;    yC=t.p[2].y;    c1=(xA*xA+yA*yA-xB*xB-yB*yB)/2.0;    c2=(xA*xA+yA*yA-xC*xC-yC*yC)/2.0;    tmp.center.x=(c1*(yA-yC)-c2*(yA-yB))/((xA-xB)*(yA-yC)-(xA-xC)*(yA-yB));    tmp.center.y=(c1*(xA-xC)-c2*(xA-xB))/((yA-yB)*(xA-xC)-(yA-yC)*(xA-xB));    return tmp;};int main(){    struct Traingle tt;    Point qq;    Circle cc;    double l1,l2,l3;    int t,k=1;    scanf("%d",&t);    while(t--)    {        scanf("%lf %lf",&tt.p[0].x,&tt.p[0].y);        scanf("%lf %lf",&tt.p[1].x,&tt.p[1].y);        scanf("%lf %lf",&tt.p[2].x,&tt.p[2].y);        scanf("%lf %lf",&qq.x,&qq.y);        l1=Dis(tt.p[0],tt.p[1]);        l2=Dis(tt.p[0],tt.p[2]);        l3=Dis(tt.p[2],tt.p[1]);        if(((l1*l1)+(l2*l2)<(l3*l3))||((l3*l3)+(l2*l2)<(l1*l1))||((l1*l1)+(l3*l3)<(l2*l2)))        {            if(((l1*l1)+(l2*l2)<(l3*l3)))            {                cc.r=l3/2.0;                cc.center.x=(tt.p[1].x+tt.p[2].x)/2.0;                cc.center.y=(tt.p[1].y+tt.p[2].y)/2.0;            }            else if(((l3*l3)+(l2*l2)<(l1*l1)))            {                cc.r=l1/2.0;                cc.center.x=(tt.p[1].x+tt.p[0].x)/2.0;                cc.center.y=(tt.p[1].y+tt.p[0].y)/2.0;            }            else if(((l1*l1)+(l3*l3)<(l2*l2)))            {                cc.r=l2/2.0;                cc.center.x=(tt.p[0].x+tt.p[2].x)/2.0;                cc.center.y=(tt.p[0].y+tt.p[2].y)/2.0;            }        }        else{            cc=CircumCircle(tt);        }        //printf("%.2lf %.2lf\n",cc.center.x,cc.center.y);        //printf("%.2lf %.2lf\n",cc.r,Dis(qq,cc.center));        printf("Case #%d: ",k++);        if(Dis(qq,cc.center)<=cc.r)            printf("Danger\n");        else printf("Safe\n");    }    return 0;}

G question:

Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4722

.. What does the senior say is DP? Okay .. No matter what it is, I have made a rule...

The rule of this question is that from xxx0 to xxx9 (X refers to random numbers, random digits, for example, 12340 to 12349 or 111111110 to 111111119), they all increase by 1, and the number is increased by 10. That is to say, each of the 10-digit periods has one and only one of them can be divisible by 10, therefore, you only need to find the number of such cycles in the random interval. Then traverse to find out the redundant front and back. For example, 5 to 35, traverse to find the excess 5 to 9, no, then traverse the excess 30 to 35, no, and then the 10 to 29 in the middle is two cycles, add 2 directly. SO 2 is out. You only need to traverse up to 20 numbers, and the rest can be calculated. Because int64 is pitted three times wa...

The Code is as follows:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;__int64 num=0, i, j, x, y, t, a, b, s, sum, pos1, pos2, flag1, flag2, z;int main(){    scanf("%I64d",&t);    while(t--)    {        s=0;        num++;        flag1=flag2=0;        scanf("%I64d%I64d",&a, &b);        for(i=a; i<=b; i++)        {            x=i;            y=i;            sum=0;            while(x)            {                z=x%10;                sum+=z;                x=x/10;            }            if(sum%10==0)            {                s++;            }            if(y%10==9)            {                pos1=y+1;                flag1=1;                break;            }        }        if(flag1==1)        {            for(i=b; i>=pos1; i--)            {                x=i;                y=i;                sum=0;                while(x)                {                    z=x%10;                    sum+=z;                    x=x/10;                }                if(sum%10==0)                {                    s++;                }                if(y%10==0)                {                    pos2=y-1;                    flag2=1;                    break;                }            }        }        if(flag1==1&&flag2==1)            s+=(pos2-pos1+1)/10;        printf("Case #%I64d: %I64d\n",num,s);    }    return 0;}


Question K:

Address: HDU 4726

The idea was discussed with my teammates, but the code was not my answer .. I am not sure about the details ..

The detailed idea is to save the number of occurrences of each upper and lower number, and then calculate the number of occurrences directly, instead of searching one by one. The first number must be determined, and the number cannot be 9 + 0. Then start searching from the combination of and 9 (in fact, it cannot be called searching .. Hash directly ).

The Code is as follows:

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char str1[2000000] ;char str2[2000000] ;int main(){    int k , i , j , l ;    int s1[11] , s2[11] , ss[11] ;    int t , tt ;    scanf("%d", &t);    for(tt = 1 ; tt <= t ; tt++)    {        memset(s1,0,sizeof(s1));        memset(s2,0,sizeof(s1));        memset(ss,0,sizeof(ss));        scanf("%s%s", str1, str2);        l = strlen(str1) ;        for(i = 0 ; i < l ; i++)        {            s1[ str1[i]-'0' ]++ ;            s2[ str2[i]-'0' ]++ ;        }        if( l == 1 && ( s1[0] == 1 || s2[0] == 1 ) )        {            if(s1[0] == 1)            {                printf("Case #%d: %c\n", tt, str2[0]);            }            else            {                printf("Case #%d: %c\n", tt, str1[0]);            }            continue ;        }        printf("Case #%d: ", tt);        int mm = -1 , m , mi , mj ;        for(i = 1 ; i <= 9 ; i++)            for(j = 1 ; j <= 9 ; j++)            {                if( s1[i] && s2[j] )                {                    m = i + j ;                    m %= 10 ;                    if(m >mm)                    {                        mm = m ;                        mi = i ;                        mj = j ;                    }                }            }        printf("%d", mm);        if(mm == 0)        {            printf("\n");            continue ;        }        s1[mi]-- ;        s2[mj]-- ;        for(k = 9 ; k >= 0 ; k--)        {            if(k == 7)                k = 7 ;            for(i = 0 ; i <= 9 ; i++)                for(j = 0 ; j <= 9 ; j++)                {                    if( s1[i] && s2[j] && (i+j)%10 == k )                    {                        m = min(s1[i],s2[j]) ;                        ss[k] += m ;                        s1[i] -= m ;                        s2[j] -= m ;                    }                }        }        for(i = 9 ; i >= 0 ; i--)        {            for( j = ss[i] ; j > 0 ; j--)            {                printf("%d", i) ;            }        }    printf("\n");    }    return 0;}


L question:

Address: HDU 4727

This question is not difficult, but it is very difficult !! This is also a question that my teammates dislike .. Sad... Submit directly without writing case... Simply sad...

Note the following two pitfalls:

1: The first person will also make an error, so when no error is found, it is the first error.

2: if one person makes an error in the process, the people following the error will follow the error instead of relying on the correct one.

It is very easy to pay attention to these two pitfalls. (Fortunately, I think of these two pitfalls .. Otherwise, it will be more disliked by teammates .... Sad ..)

The Code is as follows:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int a[1000000];int main(){    int t, num=0, n, i, j, x;    scanf("%d",&t);    while(t--)    {        num++;        scanf("%d",&n);        x=0;        int pos;        for(i=0;i<n;i++)        {            scanf("%d",&a[i]);        }        for(i=1;i<n;i++)        {            if(a[i]!=a[i-1]+1)            {                x++;                pos=i;            }        }        printf("Case #%d: ",num);        if(x==1)            printf("%d\n",pos+1);        else            printf("1\n");    }    return 0;}


2013 Chengdu Invitational competition solution report

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.