Codeforces Round 908 (Div. 2)A~D

1.A

结论题,最后一个谁赢------>最后一组谁赢------->谁是最终赢家

#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 1e6+5;
const int mod = 998244353;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
 
inline void solve() {
	int n; cin >> n;
	string s; cin >> s;
	cout << s[n - 1] << '\n';
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

2.B

找出每个数字出现的次数,若是超过两个不同的数字各自出现次数不小于2就可以

#include<bits/stdc++.h>
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define endl "\n"
using namespace std;
using ll = long long;
using db = double;
const int maxn = 1e6;
const int N = 1e6;
 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		vector<int> a(n), b(n, 1);
		vector<vector<int>>pos(105);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			pos[a[i]].push_back(i);
		}
 
		bool flag1 = 1, flag2 = 1;
		bool success = 0;
		for (int i = 1; i <= 100; i++) {
			if (pos[i].size() < 2)continue;
			if (flag1) { b[pos[i][0]] = 2; flag1 = 0; }
			else if (flag2) { b[pos[i][0]] = 3; flag2 = 0; }
			if (flag1 == 0 && flag2 == 0) { success = 1; break; }
		}
 
		if (success) for (auto i : b)cout << i << " ";
		else cout << -1;
		cout << endl;
	}
	return 0;
}

3.C

从最后一位开始,每次迭代就是按照最后一位数字往前挪,挪到谁谁就是下一个最后一位


#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
const int mod = 998244353;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
 
inline void solve() {
	int n, k; cin >> n >> k;
	vector<int>b(n + 1);
	bool fg[maxn] = { };
	int maxx = 0;
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		maxx = max(maxx, b[i]);
	}
 
	if (maxx <= n || b[n] == n) {
		cout << "Yes\n";
		return;
	}
	if (b[n] > n) {
		cout << "No\n";
		return;
	}
	int t = b[n];
	fg[n] = 1;
	int m = n;
	while (k--) {
		if (t > n) {
			cout << "No\n";
			return;
		}
		m = (m - t + n) % n;
		t = b[m];
 
		if (fg[m]) {
			cout << "Yes\n";
			return;
		}
		else
			fg[m] = 1;
	}
	cout << "Yes\n";
	return;
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

4.D

每一个bi插入小于该bi的最大aj前面

#include<bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
const int mod = 998244353;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
 
inline void solve() {
	int n, m; cin >> n >> m;
	vector<ll>a(n);
	vector<ll>b(m);
 
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	sort(b.begin(), b.end(), greater<ll>());
	int ans = 0;
	for (int i = 0; i < n; i++) {
		while (b[ans] >= a[i] && ans < b.size()) {
			cout << b[ans++] << ' ';
		}
			cout << a[i] << ' ';
	}
	while (ans < b.size())cout << b[ans++] << ' ';
	
	cout << '\n';
}
 
signed main(){
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	std::cout.tie(0);
 
	int t = 1;
	cin >> t;
	while (t--)
		solve();
 
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值