C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了。
/************************************************ * Author :Running_Time * Created Time :2015/11/8 星期日 22:41:11 * File Name :A.cpp ************************************************/ #include <bits/stdc++.h> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = acos (-1.0); int a[110][220]; int main(void) { int n, m; cin >> n >> m; for (int i=1; i<=n; ++i) { for (int j=1; j<=2*m; ++j) cin >> a[i][j]; } int ans = 0; for (int i=1; i<=n; ++i) { for (int j=1; j<=2*m-1; j+=2) { if (a[i][j] == 1 || a[i][j+1] == 1) ans++; } } cout << ans; //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. "; return 0; }
题意:n个数字分成n/k块,每块有k个数字,问n个数字,其中每一块第一个数字不是b[i]且该k个数字组成的数字能整除a[i]的方案数
分析:直接说方法吧,最大的数字比如999999除以a[i]就是所有在99999范围内a[i]的倍数,然后减去以b[i]开头的那些数字就是一块的方案数。我脑子没转过弯,用乘法一个一个乘,当然超时,怎么没想到除呢,还想用DP? (a[i] < 10 ^ k),(卒
/************************************************ * Author :Running_Time * Created Time :2015/11/8 星期日 22:41:14 * File Name :B.cpp ************************************************/ #include <bits/stdc++.h> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = acos (-1.0); ll a[N], b[N]; ll get_max(int k) { ll ret = 0; for (int i=1; i<=k; ++i) { ret = ret * 10 + 9; } return ret; } ll get_b_max(ll x, int k) { ll ret = x; for (int i=1; i<k; ++i) { ret = ret * 10 + 9; } return ret; } ll get_b_min(ll x, int k) { ll ret = x; for (int i=1; i<k; ++i) { ret = ret * 10; } return ret; } ll multi_mod(ll a, ll b) { ll ret = 0; while (b) { if (b & 1) { ret += a; if (ret >= MOD) ret -= MOD; } b >>= 1; a <<= 1; if (a >= MOD) a -= MOD; } return ret; } int main(void) { int n, k; cin >> n >> k; int m = n / k; for (int i=1; i<=m; ++i) { cin >> a[i]; } for (int i=1; i<=m; ++i) { cin >> b[i]; } ll ans = 1, mx = get_max (k); for (int i=1; i<=m; ++i) { ll cnt = mx / a[i] + 1; ll bmn = get_b_min (b[i], k), bmx = get_b_max (b[i], k); cnt -= (bmx / a[i] - bmn / a[i]); if (bmn % a[i] == 0) cnt--; ans = multi_mod (ans, cnt); } cout << ans << endl; //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s. "; return 0; }