浪潮杯

来源:互联网 发布:js和jsp交互 编辑:程序博客网 时间:2024/04/30 03:42
//Problem: Quadrat/*这题属于打表找规律题。。半天题没读懂。。学了一波字符串转数字的操作。sprintf(a, "", b);sscanf(a, "", b);*/int n, K;bool Judge(char *s1, char *s2) {    string a(s1), b(s2);    int x1 = n - a.size(), x2 = n - b.size();    if(x1 > 0) while(x1--) a = "0" + a;    if(x2 > 0) while(x2--) b = "0" + b;    //cout << a << endl << b << endl;    for(int i = 0, j = a.size()-1, k = b.size()-1; i < n; i++, j--, k--) {        int d = abs(a[j]-b[k]);        if(min(d, 10-d) > K) return false;    }    return true;}int main() {    int T;    scanf("%d", &T);    while(T--) {        char s1[20], s2[20];        scanf("%d%d", &n, &K);        /*        int m = 1, cnt = 0;        for(int i = 0; i < n; i++) m *= 10;        for(int i = 0; i < m; i++) {            sprintf(s1, "%d", i);            sprintf(s2, "%d", i*i);            if(Judge(s1, s2)) cnt++;        }        //printf("%d\n", cnt);*/        LL ans;        if(K == 1 || K == 0) ans = pow(2*K+1, n-1)*4;        else ans = pow(2*K+1, n-1)*8;        printf("%lld\n", ans);    }    return 0;}

原创粉丝点击