hdoj 3184 All Can Do

来源:互联网 发布:合肥工业大学网络公选 编辑:程序博客网 时间:2024/06/01 19:01

All Can Do

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 550    Accepted Submission(s): 206


Problem Description
Construct a number N follows three below restrictions:
1. T-1 <= Log10N < T, ( 0 < T <= 100 )
2. 90 mod b = 0
3. N mod b = 0
Please help me find the biggest N.

Input
The first line contains an integer t means the number of test cases.
Then each line will contain two integers T and b.

Output
For each case, output N in one line, if there is no such answer, output "Impossible!".

Sample Input
32 451 102 5

Sample Output
90Impossible!95
巧法:
 
#include<stdio.h>#include<string.h>#include<math.h>int T,b;void solve(){    int i;     if(b==1||b==3||b==9)//T个9     {        for(i=0;i<T;i++)        {            printf("9");        }        printf("\n");    }    else if(b==2)//T-1个9 一个8     {        for(i=0;i<T-1;i++)        {            printf("9");        }        printf("8\n");    }    else if(b==5)//T-1个9 一个5     {        for(i=0;i<T-1;i++)        {            printf("9");        }        printf("5\n");    }    else if(b==6)//T-1个9 一个6     {        for(i=0;i<T-1;i++)        {            printf("9");        }        printf("6\n");    }    else//T-1个9 一个0     {        for(i=0;i<T-1;i++)        printf("9");        printf("0\n");    }}int main(){    int t;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&T,&b);        if(90%b||T==1&&b>=10)        {            printf("Impossible!\n");            continue;        }        solve();    }    return 0;}

0 0