Codeforces Round #792 (Div. 1 + Div. 2) 补题
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
typedef long long LL;
typedef pair<int, int> PII;
const int N = 200010, M = 60, INF = 0x3f3f3f3f;
int a[N], b[N];
bool check(int a, int b)
{
for(int i = 0; i < n; i++)
{
if(v[i][a] != nv[i][b] || v[i][b] != nv[i][a]) return false;
}
return true;
}
int n;
vector<int> v[N], nv[N];
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
typedef long long LL;
typedef pair<int, int> PII;
const int N = 200010, M = 60, INF = 0x3f3f3f3f;
int a[N], b[N];
PII bs[N];
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;
}

浙公网安备 33010602011771号