codeforces 913(a,b,c,d)

A

被诈骗了,其实就是打印初始点所在行列的除初始点以外的所有点

ACcode

#include<iostream>

using namespace std;

void solve() {
	char c; cin >> c;
	int a; cin >> a;
	for (int i = 1; i <= 8; i++) {
		if (i != a) {
			cout << c << i << '\n';
		}
	}
	for (char b = 'a'; b <= 'h'; b++) {
		if (b != c) {
			cout << b << a << '\n';
		}
	}
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

B

用两个vector记住大写字母小写字母的位置,再打一个桶标记是否删除该点

#include<iostream>
#include<string>
#include<vector>

using namespace std;

void solve() {
	string str;
	cin >> str;
	int n = str.size();
	vector<bool>p(n + 3);
	vector<int>d1, d2;//小写位置,大写位置

	for (int i = 0; i < n + 3; i++)p[i] = 1;
	for (int i = 0; i < n; i++) {
		if (str[i] != 'B' && str[i] != 'b') {
			if (str[i] >= 97 && str[i] <= 122) {
				d1.push_back(i);
				continue;
			}else{//大写
				d2.push_back(i);
				continue;
			}
		}
		if (str[i] == 'b') {//删掉小写
			if (d1.empty())continue;
			int pl = d1.back();
			d1.pop_back();
			p[pl] = 0;
			continue;
		}
		if (str[i] == 'B') {
			if (d2.empty())continue;
			int p2 = d2.back();
			d2.pop_back();
			p[p2] = 0;
			continue;
		}
	}
	for (int i = 0;  i < n; i++) {
		if (p[i]) {
			if (str[i] != 'b' && str[i] != 'B')cout << str[i];
		}
	}
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}    

C

开一个map记录n个字母中每个字母出现的次数,找到最大次数ma,如果ma大于n的一半,那么就剩下(n-(n-ma))
如果ma小于n的一半,如果n是偶数,则剩下0个,如果n是奇数,则剩下一个

#include<iostream>
#include<string>
#include<map>
#include<cmath>

using namespace std;

void solve() {
	int n; cin >> n;
	string str; cin >> str;
	map<char, int>mp;
	for (auto x : str) mp[x]++;
	int ma = -1;
	for (auto [x, y] : mp)ma = max(ma, y);
	if (ma > (n / 2))cout << 2 * ma - n << '\n';
	else if (n & 1)cout << 1 << '\n';
	else cout << 0 << '\n';
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

D

#include<iostream>

using namespace std;

const int M = 2e5 + 9;
using ll = long long;
ll li[M], ri[M];//左边界,右边界
int n;

bool check(ll x) {//二分最大移动距离k,找k的最小值
	ll L = 0; ll R = 0;
	for (int i = 1; i <= n; i++) {
		ll jr = R + x; ll jl = L - x;
		if (jl > ri[i] || jr < li[i])return false;
		L = max(li[i], jl); R = min(ri[i], jr);
	}
	return true;
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> li[i] >> ri[i];
	ll j = 0; ll k = 1e9;
	while (j < k) {
		ll mid = j + k >> 1;
		if (check(mid))k = mid;
		else j = mid + 1;
	}
	cout << k << '\n';
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值