3903 - PHONE Asia - Seoul - 2007/2008

本文介绍了如何将手机号码转化为电话图表(Phone Plot),并根据形成的几何图形的最小重构线段数(MNDS)将其分类为EXCELLENT、GOOD或BAD。具体来说,MNDS小于等于3的号码为EXCELLENT,等于4的为GOOD,大于等于5的为BAD。题目提供了输入输出样例,要求程序根据MNDS判断手机号码的类别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3903 - PHONE
Asia - Seoul - 2007/2008
PDF Submit Ranking

 

Mobile phones prevail in everyday life. Every mobile phone has a number pad for users to dial the telephone number. Figure 1 shows a typical layout of number pads, which can be represented as 4 by 3 rectangular cells. We know that some mobile phone numbers are easy to memorize, since entering in sequence of digits implies an easy-to-remember geometric figure.

 

/epsfbox{p3903a.eps}

For each phone number, we can make a corresponding geometric figure, Phone Plot, which is a sequence of connected line segments. Assume that a phone number with n digits is d1 d2 d3...dn-1 dn . The first line segment of Phone Plot is a line segment connecting the center points of pad d1 and pad d2 . The second line segment of Phone Plot connects the center points of pad d2 and d3 . In a similar way the k -th line segment connects the center points of pad dk and pad dk+1 , and the last segment connects dn-1 and dn .

Let us show a few examples. The Phone Plot for the number 1023289873 is shown as the thick lines in Figure 2(a). Figure 2(b) shows that the Phone Plot for a number 1159533969.

 

/epsfbox{p3903b.eps}

You should note that some connecting line segments may overlap other line segment collinearly.

We characterize a Phone Plot by the Minimal Number of Decomposing Segments(MNDS). MNDS is the minimal number of line segments to reconstruct the given Phone Plot. So we easily find that the MNDS of the number 1023289873 is 5, and the MNDS of 1159533969 is 3. If the Phone Plot is reduced to a single point for a number (e.g., 0000000000), then MNDS of such a point Phone Plot is defined 0.

We want to classify the phone number into three disjoint classes; EXCELLENT, GOOD and BAD by the complexity of Phone Plot. Thus if the MNDS of Phone Plot is at most 3, then this number is classified to EXCELLENT. If MNDS is exactly 4, then this number is classified to GOOD. If the MNDS is greater than or equal to 5, that number is classified to BAD.

According to this classification, we say 1023289873 is BAD and 1159533969 is EXCELLENT. Figure 3 shows another example with 5233999008. Since the MNDS of 5233999008 is 5, so this number is BAD.

 

/epsfbox{p3903c.eps}

You have to decide whether the phone number given is EXCELLENT or GOOD or BAD according to the MNDS of the Phone Plot.

 

Input 

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a string representing a phone number. The length of a phone number string is greater than 5 and less than 20.

 

Output 

Your program is to write to standard output. For each test case, print EXCELLENT or GOOD or BAD in a line.

 

Sample Input 

 

4 
1023289873 
1159533969 
147258052322 
5233999008

 

Sample Output 

 

BAD 
EXCELLENT 
GOOD 
BAD

 


Seoul 2007-2008
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main()
{
   // freopen("in.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int map[10][10];
        int h[3]={0},s[2]={0},s2[6]={0},t[18]={0},x1=0,x2=0;
        memset(h,0,sizeof(h));
        memset(s,0,sizeof(s));
        memset(s2,0,sizeof(s2));
        memset(t,0,sizeof(t));
        memset(map,0,sizeof(map));
        string str;
        cin>>str;
        int len=str.size();
        for(int i=1; i<len; i++)
        {
            int a=str[i-1]-'0';
            int b=str[i]-'0';
            if(a==b) continue;
            if(map[a][b]==1) continue;
            map[a][b]=1;
            if(a>0&&b>0&&((a-1)/3==(b-1)/3))//same line
            {
                int t=(a-1)/3;
                h[t]=1;
            }
            else if(((a%3==2)&&(b%3==2))||(a%3==2&&b==0)||(a==0&&b%3==2))
            {
                if(s2[0]!=1)
                {
                    if((a==2&&b==0)||(a==0&&b==2)) s2[0]=1;
                    else if((a==2&&b==8)||(a==8&&b==2)) s2[1]=1;
                    else if((a==0&&b==5)||(a==5&&b==0)) s2[2]=1;
                    else if((a==2&&b==5)||(a==5&&b==2)) s2[3]=1;
                    else if((a==5&&b==8)||(a==8&&b==5)) s2[4]=1;
                    else if((a==8&&b==0)||(a==0&&b==8)) s2[5]=1;
                }
            }
            else if(a>0&&b>0&&(a%3==b%3))
            {
                int t=a%3;
                s[t]=1;
            }
            else
            {
                if((a==1&&b==5)||(a==5&&b==1)) x1=1;
                else if((a==1&&b==9)||(a==9&&b==1)) x1=1;
                else if((a==5&&b==9)||(a==9&&b==5)) x1=1;
                else if((a==3&&b==5)||(a==5&&b==3)) x2=1;
                else if((a==3&&b==7)||(a==7&&b==3)) x2=1;
                else if((a==5&&b==7)||(a==7&&b==5)) x2=1;
                else if((a==4&&b==8)||(a==8&&b==4)) t[0]=1;
                else if((a==7&&b==0)||(a==0&&b==7)) t[1]=1;
                else if((a==2&&b==6)||(a==6&&b==2)) t[2]=1;
                else if((a==2&&b==4)||(a==4&&b==2)) t[3]=1;
                else if((a==6&&b==8)||(a==8&&b==6)) t[4]=1;
                else if((a==9&&b==0)||(a==0&&b==9)) t[5]=1;
                else if((a==1&&b==6)||(a==6&&b==1)) t[6]=1;
                else if((a==1&&b==8)||(a==8&&b==1)) t[7]=1;
                else if((a==1&&b==0)||(a==0&&b==1)) t[8]=1;
                else if((a==3&&b==4)||(a==4&&b==3)) t[9]=1;
                else if((a==3&&b==8)||(a==8&&b==3)) t[10]=1;
                else if((a==3&&b==0)||(a==0&&b==3)) t[11]=1;
                else if((a==7&&b==2)||(a==2&&b==7)) t[12]=1;
                else if((a==7&&b==6)||(a==6&&b==7)) t[13]=1;
                else if((a==9&&b==4)||(a==4&&b==9)) t[14]=1;
                else if((a==9&&b==2)||(a==2&&b==9)) t[15]=1;
                else if((a==4&&b==0)||(a==0&&b==4)) t[16]=1;
                else if((a==6&&b==0)||(a==0&&b==6)) t[17]=1;
            }
        }
        int sum=0;
        for(int i=0; i<3; i++) if(h[i]==1) sum++;
        for(int i=0; i<2; i++) if(s[i]==1) sum++;
        if(x1==1) sum++;
        if(x2==1) sum++;
        for(int i=0; i<18; i++) if(t[i]==1) sum++;
        if(s2[0]==1||(s2[1]==1&&s2[2]==1)||(s2[3]==1&&s2[4]==1&&s2[5]==1)
                ||(s2[1]==1&&s2[5]==1)||(s2[2]==1&&s2[3]==1)) sum++;
        else
        if(s2[1]==1||(s2[3]==1&&s2[4]==1)) sum++;//就是这两个IF语句出错了
        else
        if(s2[2]==1||(s2[4]==1&&s2[5]==1))  sum++;
        else
        {
            for(int i=3; i<=5; i++)
                if(s2[i]==1) sum++;
        }
        if(sum<=3)  printf("EXCELLENT/n");
        else if(sum==4) printf("GOOD/n");
        else printf("BAD/n");
        //printf("%d/n",sum);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值