Codeforces Round #753 (Div. 3)

A. Linear Keyboard

大水题,暴力就行
参考代码:

#include <iostream>
#include <unordered_map>
#include <cmath>
using namespace std;

const int N = 50;
unordered_map<char, int> q;

int main()
{
	string s1, s2;
	int T;
	cin >> T;
	
	while(T--)
	{
		cin >> s1 >> s2;
		for(int i = 0; i < s1.size(); i++)
			q[s1[i]] = i + 1;
		int ans = 0;
		for(int i = 1; i < s2.size(); i++)
		{
			if(s2[i] == s2[i - 1]) continue;
			ans += abs(q[s2[i]] - q[s2[i - 1]]);
		}
		
		cout << ans << endl;
	}
} 

B. Odd Grasshopper

打表找规律,发现偶数的规律是:- + + -
奇数的规律是:+ - - +
在分类讨论,在取余求答案即可
参考代码:

#include <iostream>
#include <cstdio>
using namespace std;

typedef long long LL;

int main()
{
	int T;
	cin >> T;
	
	while(T--)
	{
		LL x, t;
		scanf("%lld%lld", &x, &t);
		
		if(x % 2 == 0)
		{
			if(t % 4 == 1) x -= t;
			else if(t % 4 == 2) x += 1;
			else if(t % 4 == 3) x += t + 1;
		}
		
		else
		{
			if(t % 4 == 1) x += t;
			else if(t % 4 == 2) x -= 1;
			else if(t % 4 == 3) x -= (t + 1);
		}
		
		printf("%lld\n", x);
	}
	return 0;
}

C. Minimum Extraction

一道排序题,先排序,在直接安题意模拟即可
参考代码:

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long LL;
const int N = 2e5 + 10;

int a[N];
LL s[N];

int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		int n;
		cin >> n;
		for(int i = 1; i <= n; i++) cin >> a[i];
		
		sort(a + 1, a + n + 1);
		
		LL ans = -2e9, sum = 0;
		for(int i = 1; i <= n; i++)
		{
			ans = max(ans, a[i] - sum);
			sum += (a[i] - sum);
		}
		
		cout << ans << endl;
	}
	return 0;
}

D. Blue-Red Permutation

感觉这题有点难想到,但想到的话,是非常简单的,哎,思维还是不过关呀,
前一部分,用可以进行减1的数字去得到,并按大小依次对应
后一部分,用可以进行加1的数字去得到,并按大小依次对应
然后枚举并判断对应的数字是否可行即可。
参考代码:

#include <iostream>
#include <algorithm>
#include <vector> 
using namespace std;

int main()
{
	int T;
	cin >> T;
	
	while(T--)
	{
		int n;
		cin >> n;
		vector<int> a(n), b, r;
		for(int i = 0; i < n; i++) cin >> a[i];
		
		char ch;
		for(int i = 0; i < n; i++)
		{
			cin >> ch;
			if(ch == 'B') b.push_back(a[i]);
			else r.push_back(a[i]);
		}
		
		sort(b.begin(), b.end());
		sort(r.begin(), r.end());
		
		bool flag = true;  int t = 1;
		for(auto i : b)
		{
			if(i < t) flag = false;
			t++;
		}
		
		for(auto i : r)
		{
			if(i > t) flag = false;
			t++;
		}
		
		if(flag) puts("YES");
		else puts("NO");
	}
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值