A.懒得写题解,但欢迎提问。
注意:Div. 4,Div. 4,Div. 4,暴力,暴力,暴力!能过,能过,能过!
#includeBusing namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int a = 0; int b = 0; char c; for (int i = 1; i <= 3; i++) { cin >> c; a += c - '0'; } for (int i = 1; i <= 3; i++) { cin >> c; b += c - '0'; } if (a == b)cout << "YES" << 'n'; else cout << "NO" << 'n'; } return 0; }
#includeCusing namespace std; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long sum = 0; int minn = 1e8; int x; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; sum += x; minn = min(minn, x); } cout << sum - minn * n<<'n'; } return 0; }
#includeusing namespace std; int n,m; char c[60][10]; int cha[60]; long long sum[60]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { sum[0] = 0; long long ans = 1e9 + 7; cin >> n >> m; for (int i = 1; i <= n; i++) { //cha[i] = 0; for (int j = 1; j <= m; j++) { cin >> c[i][j]; if (i != 1) { // cha[i] += c[i][j] - c[i - 1][j]; } } //sum[i] = sum[i - 1] + cha[i]; } long long summ; for(int i=1;i D #includeEusing namespace std; int n, m; int c[300][300]; int cha[60]; long long suma[1010], sumb[1010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long ans = 0; cin >> n >> m; memset(suma, 0, sizeof(suma)); memset(sumb, 0, sizeof(sumb)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> c[i][j]; suma[i - j + n + m] += c[i][j]; sumb[i + j] += c[i][j]; } int nm = max(n, m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { ans = max(ans, suma[i - j + n + m] + sumb[i + j] - c[i][j]); } } cout << ans << 'n'; } return 0; } #includeFusing namespace std; int n, m; long long c[500005]; long long suma[500005]; int test(int low, int high, long long key) { long long mid = 0; while (high > low) { mid = (high + low) / 2; if (suma[mid] >= key) { high = mid; } else { low = mid + 1; } } return high; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { long long ans = 0; cin >> n >> m; memset(suma, 0, sizeof(suma)); for (int i = 1; i <= n; i++) { cin >> c[i]; } sort(c + 1, c + 1 + n); suma[0] = 0; for (int i = 1; i <= n; i++) { suma[i] = suma[i - 1] + c[n - i + 1]; //cout << suma[i] << endl; } long long q; while (m--) { cin >> q; if (q == 0)cout << 0 << 'n'; else { int ans = test(1, n, q); if (suma[ans] >= q) cout << ans << 'n'; else cout << -1 << 'n'; } } } return 0; } #includeG 暑期编程PK赛 得CSDN机械键盘等精美礼品!using namespace std; int n, m; int c[500005], a[500005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int q; cin >> q; map t; while (q--) { int k = 0; int x; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> x; t[x]++; if (t[x] == m) a[++k] = x; } sort(a + 1, a + 1 + k); if (k == 0) { cout << -1 << 'n'; t.clear(); continue; } int cnt = 1; int ans = 1, anl = a[1], anr = a[1]; int cnl = a[1], cnr = 0; for (int i = 2; i <= k; i++) { if (a[i] - a[i - 1] == 1) { cnt++; if (cnt > ans) { ans = cnt; anl = cnl; anr = a[i]; } } else { cnt = 1; cnl = a[i]; } } if (ans > 0)cout << anl << " " << anr<<'n'; t.clear(); } return 0; }



