Codeforces Round #792 (Div. 1 + Div. 2) 補題
阿新 • • 發佈:2022-05-22
A~D
A
思路:假如不是兩位數,那麼一定可以找到最大的那個數,直接輸出即可。如果是兩位數,那就是第二位的數字
void solve() { string st; cin >> st; int lens = st.size(); if(lens == 2) { cout << st[1] << endl; return ; } for(int i = 0; i < st.size(); i++) { a[i] = st[i] - '0'; } sort(a, a + lens); cout << a[0] << endl; }
B
思路:因為\(a < b < c\),且由於x mod y = a, y mod z = b, z mod x = c
從前往後看,x mod y = a,那就使\(x\)比\(y\)多\(a\)就行了, 所以x = y + a, y = z + b, 按理說\(z\)應該等於x + c,但是根據題目可知\(z\)是絕對比\(x\)小的數,所以一個小數\(mod\)一個大數,結果為小數,即直接讓z = c, 然後再代回去,y = c + b, x = a + b + c.
void solve() { int x, y, z; cin >> x >> y >> z; cout << x + y + z << ' ' << y + z << ' ' << z << endl; }
C~D題不是自己想出來的,原作者是Jakon(點這裡)
C
void solve() { int m; cin >> n >> m; for(int i = 0; i < n; i++) v[i].clear(); for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j++) { int x; cin >> x; v[i].push_back(x); } nv[i] = v[i]; sort(v[i].begin(), v[i].end()); } bool flag = true; int pos1 = -1, pos2 = -1; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(v[i][j] != nv[i][j]) { if(pos1 == -1 || pos1 == j) pos1 = j; else if(pos2 == -1 || pos2 == j) pos2 = j; else flag = false; } } } if(!flag) { puts("-1"); return ; } if(pos1 == -1 && pos2 == -1) puts("1 1"); else if(check(pos1, pos2)) cout << pos1 + 1 << ' ' << pos2 + 1 << endl; else puts("-1"); }
D
void solve()
{
int n, k;
cin >> n >> k;
int c[N];
for(int i = 1; i<= n; i++) cin>> a[i];
LL ans = 0;
for(int i = 1; i <= n; i++)
{
bs[i] = {a[i] + i, i};
}
sort(bs + 1, bs + 1 + n, qh);
for(int i = 1; i <= k; i++) c[i] = bs[i].second;
sort(c + 1, c + 1 + k);
int cnt = 0;
for(int i = 1; i <= n; i ++)
{
if(cnt < k && i == c[cnt + 1]) cnt ++;
else ans += a[i] + cnt;
}
cout << ans << endl;
}