10月15日贝壳找房研发类试卷题解
全AC。
1、傻傻的搏斗
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; typedef long long LL; int main() { LL T, X, A, C, B, D, Y; cin >> T; while (T--) { cin >> X >> A >> C >> Y >> B >> D; LL XIAOZHI = (X / B - 1) * D; // 不用判断X是否小于等于B if (X % B != 0) XIAOZHI += D; LL XIAOCHUN = (Y / A - 1) * C; if (Y % A != 0) XIAOCHUN += C; if (XIAOCHUN == XIAOZHI) puts("TIE"); else if (XIAOCHUN < XIAOZHI) puts("XIAOZHI"); else puts("XIAOCHUN"); } return 0; }
2、简单的表达式计算
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; typedef long long LL; LL compute(int pos, string str, int n) { LL len = str.size(), res = 0; for (int i = pos; i < len; i++) { if (str[i] >= 'A') res = res * n + str[i] - 'A' + 10; else res = res * n + str[i] - '0'; } return res; } LL str2dec(string str) { int len = str.size(); if (len == 1) return str[0] - '0'; if (len == 2) { if (str[0] == '0') return str[1] - '0'; return (str[0] - '0') * 10 + str[1] - '0'; } if (str[0] == '0' && str[1] == 'x') { return compute(2, str, 16); } else if (str[0] == '0') { return compute(1, str, 8); } return compute(0, str, 10); } int main() { LL ans = 0; string str; cin >> str; int len = str.size(); string s = ""; int pre = 0; for (int i = 0; i < len; i++) { if (str[i] == '+') { LL tmp = str2dec(s); //cout << tmp << endl; s = ""; if (!pre) ans += tmp; else ans -= tmp; pre = 0; } else if (str[i] == '-') { LL tmp = str2dec(s); //cout << tmp << endl; s = ""; if (!pre) ans += tmp; else ans -= tmp; pre = 1; } else s += str[i]; } LL tmp = str2dec(s); //cout << tmp << endl; if (!pre) ans += tmp; else ans -= tmp; cout << ans << endl; return 0; }
3、找寻序列
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; typedef long long LL; LL dp[1005][1005]; int main() { for (int i = 1; i < 1005; i++) dp[1][i] = 1; for (int i = 2; i < 1005; i++) { // 长度N for (int j = 1; j < 1005; j++) { // 尾值M int tmp = sqrt(j); for (int k = 1; k <= tmp; k++) { if (j % k == 0) { dp[i][j] += dp[i - 1][k]; dp[i][j] %= mod; dp[i][j] += dp[i - 1][j / k]; dp[i][j] %= mod; } } if (tmp * tmp == j) { dp[i][j] -= dp[i - 1][tmp]; dp[i][j] %= mod; } } } int N, M; while (cin >> N >> M) { cout << dp[N][M] << endl; } return 0; }#贝壳找房##题解#