Educational Codeforces Round 135题解(A ~ D )

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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值