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();
}
相关推荐
然我16 分钟前
链表指针玩不转?从基础到双指针,JS 实战带你破局
前端·数据结构·算法
EndingCoder24 分钟前
算法与前端的可访问性
前端·算法·递归·树形结构
开开心心_Every43 分钟前
可增添功能的鼠标右键优化工具
开发语言·pdf·c#·计算机外设·电脑·音视频·symfony
ysa0510301 小时前
竞赛常用加速技巧#模板
c++·笔记·算法
7 971 小时前
C语言基础知识--文件的顺序读写与随机读写
java·数据结构·算法
2401_841003981 小时前
Kubernetes 资源管理全解析
算法·贪心算法
☆璇2 小时前
【数据结构】排序
c语言·开发语言·数据结构·算法·排序算法
艾莉丝努力练剑5 小时前
【LeetCode&数据结构】单链表的应用——反转链表问题、链表的中间节点问题详解
c语言·开发语言·数据结构·学习·算法·leetcode·链表
_殊途6 小时前
《Java HashMap底层原理全解析(源码+性能+面试)》
java·数据结构·算法
珊瑚里的鱼10 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法