OJ-Problems-Source/HDOJ/4541_autoAC.cpp

74 lines
3.3 KiB
C++
Raw Normal View History

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int s[20][100];
void inite()
{
s[3][0]= 4; s[3][1] = 1, s[3][2] = 2, s[3][3] = 6, s[3][4] = 10;
s[4][0] = 4;s[4][1] = 0, s[4][2] = 4, s[4][3] = 5, s[4][4] = 9;
s[5][0] = 6; s[5][1] = 3, s[5][2] = 7, s[5][3] = 8, s[5][4] = 40;
s[5][5] = 50, s[5][6] = 60;
s[6][0] = 6, s[6][1] = 11, s[6][2] = 12, s[6][3] = 20, s[6][4] = 30;
s[6][5] = 80, s[6][6] = 90;
s[7][0] = 3, s[7][1] = 15, s[7][2] = 16, s[7][3] = 70;
s[8][0] = 13, s[8][1] = 13, s[8][2] = 14, s[8][3] = 18, s[8][4] = 19;
s[8][5] = 41, s[8][6] = 42, s[8][7] = 46, s[8][8] = 51, s[8][9] = 52;
s[8][10] = 56,s[8][11] =61 ,s[8][12] = 62,s[8][13] = 66;
s[9][0] = 22, s[9][1] = 17,s[9][2] = 21, s[9][3] = 22,s[9][4] = 26;
s[9][5] = 31, s[9][6] = 32,s[9][7] = 36, s[9][8] = 44,s[9][9] = 45;
s[9][10] = 49,s[9][11] = 54,s[9][12] = 55, s[9][13] = 59,s[9][14] = 64;
s[9][15] = 65, s[9][16] = 69,s[9][17] = 81, s[9][18] = 82,s[9][19] = 86;
s[9][20] = 91, s[9][21] = 92, s[9][22] = 96;
s[10][0] = 25, s[10][1] = 24,s[10][2] = 25, s[10][3] = 29,s[10][4] = 34;
s[10][5] = 35, s[10][6] = 39,s[10][7] = 43, s[10][8] = 47,s[10][9] = 48;
s[10][10] = 53, s[10][11] = 57,s[10][12] = 58, s[10][13] = 63,s[10][14] = 67;
s[10][15] = 68, s[10][16] = 71,s[10][17] = 72, s[10][18] = 76,s[10][19] = 84;
s[10][20] = 85, s[10][21] = 89,s[10][22] = 94, s[10][23] = 95,s[10][24] = 99;
s[10][25] = 100;
s[11][0] = 15, s[11][1] = 23,s[11][2] = 27,s[11][3] = 28,s[11][4] = 33;
s[11][5] = 37, s[11][6] = 38,s[11][7] = 74,s[11][8] = 75,s[11][9] = 79;
s[11][10] = 83, s[11][11] = 87,s[11][12] = 88,s[11][13] = 93,s[11][14] = 97;
s[11][15] = 98;
s[12][0] = 3,s[12][1] = 73,s[12][2] = 77,s[12][3] = 78;
}
int main()
{
inite();
int T, cas = 0;
for(scanf("%d", &T); T--; )
{
int a, b;
scanf("%d%d", &a, &b);
if((a < 3) || a > 12)
printf("Case #%d: -1\n", ++cas);
else
{
if(((s[a][0] < b) && (a != 9)) || ((a == 9) && (s[a][0] + 4< b)))
printf("Case #%d: -1\n", ++cas);
else
{
if(a == 9)
{
if(b <= 22)
printf("Case #%d: %d\n", ++cas, s[a][b]);
else if(b == 23)
printf("Case #%d: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", ++cas);
else if(b == 24)
printf("Case #%d: 20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", ++cas);
else if(b == 25)
printf("Case #%d: 60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", ++cas);
else if(b == 26)
printf("Case #%d: 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", ++cas);
}
else
printf("Case #%d: %d\n", ++cas, s[a][b]);
}
}
}
return 0;
}