inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
int t, aa[3];
intmain(){ t = read(); while (t --> 0) { aa[0] = read(); aa[1] = read(); aa[2] = read(); std::sort(aa, aa + 3); if (aa[0] + aa[1] >= aa[2]) puts("1"); elseprintf("%d\n", aa[2] - aa[1] - aa[0] + 1); } return0; }
inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
int t; longlongint ans; int n, m, mat[100 + 10][100 + 10];
longlongintcalc(std::vector<int>& vec){ longlongint ans = 0; std::sort(vec.begin(), vec.end()); for (auto v : vec) { ans += std::abs(v - vec[vec.size() / 2]); } return ans; }
intmain(){ t = read(); while (t --> 0) { ans = 0; n = read(); m = read(); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { mat[i][j] = read(); } } for (int lx = 1; lx <= (n + 1) / 2; ++lx) { for (int ly = 1; ly <= (m + 1) / 2; ++ly) { int rx = n - lx + 1, ry = m - ly + 1; std::vector<int> ff; ff.push_back(mat[lx][ly]); if (lx != rx) ff.push_back(mat[rx][ly]); if (ly != ry) ff.push_back(mat[lx][ry]); if (lx != rx && ly != ry) ff.push_back(mat[rx][ry]); ans += calc(ff); } } printf("%lld\n", ans); } return0; }
C. Bargain
题意简述
给一个长度为 n 的数字,现在允许删去至多一段连续的数位来得到一个新数,全删了就是 0,求所有可以得到的数字之和。
intmain(){ cin >> s; n = (int) s.size(); longlongint ans = 0, sum = 0, p = 1; for (longlongint i = n - 1; i >= 0; --i) { longlongint k = (i * (i + 1) / 2 % ha * p % ha + sum) % ha; sum = (sum + p * (n - i) % ha) % ha; p = p * 10 % ha; ans = (ans + (s[i] - '0') * k % ha) % ha; } printf("%lld\n", ans); return0; }
inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
constint MAXM = 2e5 + 10;
std::map<coo, int> idx; int cnt; intid(coo x){ if (idx[x]) return idx[x]; return idx[x] = ++cnt; }
int n, m; longlongint sx, sy, tx, ty; int s, t; coo coors[MAXM];
inlineintread(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }