NYOJ 52 无聊的小明 【模拟】
发布时间:2020-12-14 02:44:10 所属栏目:大数据 来源:网络整理
导读:无聊的小明 时间限制: 3000 ?ms ?|? 内存限制: 65535 ?KB 难度: 3 描述 ????? 这天小明十分无聊,没有事做,但不甘于无聊的小明聪明的想到一个解决无聊的办法,因为他突然对数的正整数次幂产生了兴趣。 众所周知,2的正整数次幂最后一位数总是不断的在重
无聊的小明
时间限制:
3000?ms ?|? 内存限制:
65535?KB
难度:
3
这道题就是模拟乘法,需要用到大数相乘和结构体的知识。最多不超过1e4; 代码: #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; const int M =1e4; struct node{ int s[15]; }; int main(){ int n; cin >> n; while(n --){ int m,k; cin >> m >> k; /* if(k == 1){ printf() }*/ node a; memset(a.s,sizeof(a.s)); int i = 1; string st; while(m){ a.s[i++] = m%10; //st += (a.s[i-1]+'0'); m /= 10; } for(int i = 1; i <= k; ++ i) st += (a.s[i]+'0'); // cout << st; int res = 0; node b = a,c; //memset(c.s,sizeof(c.s)); string str; while(res < M){ memset(c.s,sizeof(c.s)); for(int i = 1; i <= k; ++ i){ for(int j = 1; j <= k; ++ j){ c.s[i+j-1] += a.s[i]*b.s[j]; c.s[i+j] += c.s[i+j-1]/10; c.s[i+j-1] %= 10; } /*str += (c.s[i]+'0'); cout << str;*/ } for(int i = 1; i <= k; ++ i) str += (c.s[i]+'0'); ++res; if(st == str) break; str.clear(); b = c; } if(res == M) cout << -1 <<endl; else cout <<res << endl; } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |