ACM学习历程—51NOD 1770数数字(循环节)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770
这是这次BSG白山极客挑战赛的A题。由于数字全部相同,乘上b必然会有循环节,于是模拟乘法,记录数据,出现循环就退出即可。
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> #include <set> #include <map> #include <queue> #include <vector> #include <string> #define LL long long using namespace std; int a, b, d, n; int main() { //freopen("test.in", "r", stdin); int T, rest, to, pre; scanf("%d", &T); for (int times = 0; times < T; ++times) { int ans = 0, tmp; scanf("%d%d%d%d", &a, &b, &d, &n); rest = to = 0; pre = -1; for (int i = 0; i < n; ++i) { tmp = a*b+to; to = tmp/10; rest = tmp%10; if (tmp == pre) { if (rest == d) ans += n-i; break; } pre = tmp; if (rest == d) ans++; } if (to != 0 && to == d) ans++; printf("%d\n", ans); } return 0; }
把每一道题当作难题去做。
posted on 2016-05-24 15:59 AndyQsmart 阅读(596) 评论(0) 编辑 收藏 举报