Educational Codeforces Round 135 比赛链接 (第一次写题解,希望可以养成习惯
A.Colored Balls: Revisited
思路:
每次都删掉数量最少的两个气球,最后留下的一定是原始数量最多的那个颜色。
代码:
int n;
int mx = 0, id = 0;
void solve()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
{
int x; cin >> x;
if (x > mx)
{
mx = x;
id = i;
}
}
cout << id << endl;
mx = 0;
}
B. Best Permutation
思路:
可以发现最大值一定是 n + (n - 1) 。那就保证遍历到 n - 2 的时候 x 的值为0就好了。
void solve()
{
cin >> n;
if (n & 1)
{
cout << 1 << ' ';
for (int i = n - 2; i > 1; i -- )
cout << i << ' ';
}
else
{
for (int i = n - 2; i >= 1; i -- )
cout << i << ' ';
}
cout << n - 1 << ' ' << n << endl;
}
C. Digital Logarithm
思路:
因为数据是 1 ~ 10^9^。所以对一个大于10的数操作后都会得到一个1 ~ 9 的数。
输入数据 a 的时候记录一下可以得到1~9的数有多少。对大于10的数操作一次(cnt + 1, 同时存入map中
输入数据 b 的时候先判断是否map中出现过, 出现过的话在a中就不用对这个数操作(cnt - 1, 没出现过就把记录的1 ~ 9 对应减一
最后cnt累再加上t[i] ( 1 < i < 10 )
int n, x;
int cnt = 0;
int t[15];
int get(int x)
{
int res = 0;
while(x)
{
res ++;
x /= 10;
}
return res;
}
void solve()
{
map<int, int> mp;
mes(t,0);
cnt = 0;
cin >> n;
for (int i = 1; i <= n; i ++ )
{
cin >> x;
if(x < 10) t[x] ++;
else
{
cnt ++;
t[get(x)] ++;
mp[x] ++;
}
}
for (int i = 1; i <= n; i ++ )
{
cin >> x;
if (x < 10) t[x] --;
else
{
if (mp[x])
{
mp[x] --;
cnt -= 1;
}
else cnt ++;
t[get(x)] --;
}
}
for (int i = 2; i < 10; i ++ )
{
if (t[i]) cnt += abs(t[i]);
}
cout << cnt << endl;
}
D. Letter Picking
思路:
因为 Alice 先手, 所以很容易证明Alice必赢或平局。
平局的话有以下两种:① aaaaa ② abba 。
相同或是回文,如果先减去前后缀相同的话如 aacbbc -- > cbbc 结果是平局,但Alice如果先取c的话Bob就无法取c了。所以先减回文再减前后缀,最后如果有剩余那就是Alice获胜。
int n;
string s;
void solve()
{
cin >> s;
n = s.size();
s = ' ' + s;
int l = 1, r = n;
while(l < r)
{
if (s[l] == s[r]) l ++, r --;
else break;
}
while(l < r)
{
if (s[l] == s[l + 1]) l += 2;
else if (s[r] == s[r - 1]) r -= 2;
else break;
}
cout << (l < r ? "Alice" : "Draw") << endl;
}