题解:根据字符个数制表如下:
3:1, 2 ,6 ,10
4:0, 4, 5 , 9
5:3, 7, 8, 40 ,50 ,60
6:11,12, 20, 30, 80 ,90
7:15 ,16 ,70
8:13, 14 ,18, 19 ,41 ,42 ,46 ,51 ,52 ,56 ,61 ,62 ,66
9:17 ,21 ,22 ,26 ,31 ,32 ,36 ,44 ,45 ,49 ,54 ,55 ,59 ,64 ,65 ,69 ,81 ,82 ,86 ,91 ,92 ,96
googol 级别特殊处理。OK!
代码:
#include <iostream> #include <string.h> #include <stdio.h> #include <map> #include <string> using namespace std; #define MAXV 100010 #define MAX 25 int mp[MAX][MAX] ={ {4, 1, 2, 6, 10}, {4, 0, 4, 5, 9}, {6, 3, 7, 8, 40, 50, 60}, {6, 11, 12, 20, 30, 80, 90}, {3, 15, 16, 70}, {13,13, 14 ,18, 19 ,41 ,42 ,46 ,51 ,52 ,56 ,61 ,62 ,66}, {26,17 ,21 ,22 ,26 ,31 ,32 ,36 ,44 ,45 ,49 ,54 ,55 ,59 ,64 ,65 ,69 ,81 ,82 ,86 ,91 ,92 ,96, 101} }; int main(){ int T,n,m; scanf("%d",&T); for(int i = 1; i <= T; i++){ scanf("%d%d",&n,&m); printf("Case #%d: ",i); if(m > mp[n-3][0]){ printf("-1\n");continue; } if(n == 9 && m > 22){ if(m == 23){ printf("10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"); } else if(m == 24){ printf("20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"); } else if(m== 25){ printf("60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"); } else if(m==26){ printf("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n"); } } else { printf("%d\n",mp[n-3][m]); } } return 0; }