Codeforces Round 908 (Div. 2)视频详解

Educational Codeforces Round 157 (A--D)视频详解

视频链接

Codeforces Round 908 (Div. 2)视频详解

A题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	bool fa = false;
	bool fb = false;
	for(int y = 1; y <= n; y ++)
	{
		for(int x = 1; x <= n; x ++)
		{

			int ca = 0, cb = 0, cat = 0, cbt = 0;
			for(int i = 0; i < n; i ++)
			{
				if(s[i] == 'A')
					ca ++;
				else
					cb ++;

				if(ca == x)
				{
					ca = 0, cb = 0;
					cat ++;
					
				}

				if(cb == x)
				{
					ca = 0, cb = 0;
					cbt ++;
				}
				if(cat == y)
				{
					if(i < n - 1)
						break;
					fa = true;
				}
				if(cbt == y)
				{
					if(i < n - 1)
						break;

					fb = true;
				}
			}

		}
	}
	if(fa && !fb)
	{
		cout << "A" << endl;
	}
	else if(fb && !fa)
	{
		cout << "B" << endl;
	}	
	else
	{
		cout << "?" << endl;
	}
}

void solve_1()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	cout << s.back() << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//t = 1;
	cin >> t;
	while(t--)
	solve_1();
}

B题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	map<int,int>st;
	for(int i = 0; i < n; i ++)
	{
		cin >> a[i];
		st[a[i]] ++;
	}

	int cnt = 0;
	for(auto [a, b]: st)
		if(b >= 2)
			cnt ++;

	if(cnt < 2)
	{
		cout << -1 << endl;
		return;
	}

	vector<int>b(n);
	int x = 1;
	for(int i = 0; i < n; i ++)
	{
		if(!b[i] && st[a[i]] > 1)
		{
			int col = 0;
			for(int j = i; j < n; j ++)
			{
				if(a[j] == a[i])
				{
					b[j] = (col) % 2 + x;
					col ++;
				}
			}
			x ++;
		}
		if(x == 3)
			break;
	}
	for(int i = 0; i < n; i ++)
	{
		if(!b[i])
			b[i] = 1;
	}
	for(int i = 0; i < n; i ++)
	{
		cout << b[i] << " ";
	}
	cout << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//t = 1;
	cin >> t;
	while(t--)
	solve();
}

C题代码

cpp 复制代码
#include <bits/stdc++.h>
 
using namespace std;
 
void solve() 
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  k = min(k, n);
  int last = n;
  for (int i = 0; i < k; i++) 
  {
    if (a[last] > n) 
    {
      cout << "No\n";
      return;
    }
    last -= a[last];
    if(last <= 0)
    	last += n;
  }
  cout << "Yes\n";
}
 
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}

D题代码

cpp 复制代码
#include<bits/stdc++.h>
#define endl '\n'
#define deb(x) cout << #x << " = " << x << '\n';
#define INF 0x3f3f3f3f
using namespace std;

bool cmp(int x, int y)
{
	return x > y;
}
void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int>a(n),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(), cmp);

	int j = 0;
	for(int i = 0; i < n; i ++)
	{
		while(j < m && b[j] >= a[i])
		{
			cout << b[j] << " ";
			j ++;
		}
		cout << a[i] << " ";
	}
	while(j < m)
		cout << b[j ++] << " ";

	cout << endl; 
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//t = 1;
	cin >> t;
	while(t--)
	solve();
}
相关推荐
刘海东刘海东14 分钟前
结构型智能科技的关键可行性——信息型智能向结构型智能的转变(修改提纲)
人工智能·算法·机器学习
pumpkin8451441 分钟前
Rust 调用 C 函数的 FFI
c语言·算法·rust
挺菜的1 小时前
【算法刷题记录(简单题)003】统计大写字母个数(java代码实现)
java·数据结构·算法
mit6.8241 小时前
7.6 优先队列| dijkstra | hash | rust
算法
2401_858286111 小时前
125.【C语言】数据结构之归并排序递归解法
c语言·开发语言·数据结构·算法·排序算法·归并排序
guygg882 小时前
基于matlab的FIR滤波器
开发语言·算法·matlab
双叶8362 小时前
(C++)学生管理系统(正式版)(map数组的应用)(string应用)(引用)(文件储存的应用)(C++教学)(C++项目)
c语言·开发语言·数据结构·c++
ysh98883 小时前
PP-OCR:一款实用的超轻量级OCR系统
算法
遇雪长安3 小时前
差分定位技术:原理、分类与应用场景
算法·分类·数据挖掘·rtk·差分定位
数通Dinner3 小时前
RSTP 拓扑收敛机制
网络·网络协议·tcp/ip·算法·信息与通信