首页 > 其他分享 >「Codeforces」寒假训练 2023 #3

「Codeforces」寒假训练 2023 #3

时间:2023-01-09 19:11:45浏览次数:54  
标签:int 2023 Codeforces long ++ 寒假 ans len printf

A. String LCM

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int q;
string s, t;
int lens, lent;
int _lcm;
char ans[N];
int len;
int gcd(int u, int v)
{
	return v == 0 ? u : gcd(v, u % v);
}
int lcm(int u, int v)
{
	return u * v / gcd(u, v);
}
bool check()
{
	int k = 0;
	for(int i = 0; i < len; i++)
	{
		if(t[k++] != ans[i]) return false;
		if(k >= lent) k = 0;
	}
	return true;
}
int main()
{
	cin >> q;
	while(q--)
	{
		cin >> s >> t;
		lens = s.length();
		lent = t.length();
		len = 0;
		_lcm = lcm(lens, lent);
		while(len < _lcm)
		{
			for(int i = 0; i < lens; i++)
			{
				ans[len++] = s[i];
			}
		}
		if(check())
		{
			for(int i = 0; i < len; i++)
			{
				printf("%c", ans[i]);
			}
			cout << endl;
		}
		else cout << "-1" << endl;
	}
	return 0;
}

B. ABBB

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int t;
char s[N];
char h[3] = "BB";
int main()
{
	cin >> t;
	char u = getchar();
	while(t--)
	{
		char ch;
		bool f = false;
		int k = 0;
		while((ch = getchar()) != '\n')
		{
			if(ch == 'A') f = true;
			else if(ch == 'B' && f)
			{
				k--;
				if(k == 0) f = false;
				else if(s[k - 1] == 'A') f = true;
				else if(s[k - 1] == 'B') f = false;
				continue;
			}
			s[k++] = ch;
		}
		s[k] = '\0';
		int len = strlen(s);
		int ans = 0;
		bool r = true;
		if(len == 0) r = false;
		for(int i = 0; i < len - 1; i++)
		{
			bool matched = true;
			for(int j = 0; j < 2; j++)
			{
				if(s[i + j] != h[j])
				{
					matched = false;
					break;
				}
			}
			if(matched)
			{
				i++;
				if(i == len - 1) r = false;
				continue;
			}
			ans++;
		}
		if(r) ans++;
		cout << ans << endl;
	}
	return 0;
}

C. Repainting Street

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int t;
int n, k;
int s[N];
int main()
{
	cin >> t;
	while(t--)
	{
		set<int> c;
		scanf("%d%d", &n, &k);
		for(int i = 0; i < n; i++)
		{
			scanf("%d", s + i);
			c.insert(s[i]);
		}
		int ans = N;
		for(set<int>::iterator it = c.begin(); it != c.end(); it++)
		{
			int res = 0;
			for(int j = 0; j < n; j++)
			{
				if(s[j] != *it)
				{
					res++;
					j += k - 1;
				}	
			}
			ans = min(ans, res);
		}
		cout << ans << endl;
	}
	return 0;
}

D. WeirdSort

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n, m;
		scanf("%d%d", &n, &m);
		int a[N];
		set<int> p;
		for(int i = 0; i < n; i++)
		{
			scanf("%d", a + i);
		}
		for(int i = 0; i < m; i++)
		{
			int x;
			scanf("%d", &x);
			p.insert(x);
		}
		int f = true;
		for(int i = 0; i < n - 1; i++)
		{
			for(int j = 0; j < n - 1 - i; j++)
			{
				if(a[j] > a[j + 1])
				{
					if(!p.count(j + 1))
					{
						f = false;
						break;
					}
					int tmp = a[j];
					a[j] = a[j + 1];
					a[j + 1] = tmp;
				}
			}
			if(!f) break;
		}
		if(f) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

E. Valera and Tubes

原题链接

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, m, k;
int cnt;
bool f, h;
int main()
{
	scanf("%d%d%d", &n, &m, &k);
	if(m % 2) f = true;
	for(int x = 1; x <= n; x++)
	{
		if(x % 2)
		{
			for(int y = 1; y <= m; y += 2)
			{
				if(cnt != k - 1)
				{
					cnt++;
					printf("2 %d %d ", x, y);
					if(f && y + 1 > m) printf("%d %d\n", x + 1, y);
					else printf("%d %d\n", x, y + 1);
				}
				else
				{
					if(!h)
					{
						h = true;
						printf("%d ", n * m - cnt * 2);
					}
					printf("%d %d ", x, y);
					if(f && y + 1 > m)
					{
						if(x != n) printf("%d %d ", x + 1, y);
					}
					else printf("%d %d ", x, y + 1);
				}
			}
		}
		else
		{
			for(int y = m; y >= 1; y -= 2)
			{
				if(f && y == m)
				{
					y++;
					continue;
				}
				if(cnt != k - 1)
				{
					cnt++;
					printf("2 %d %d %d %d\n", x, y, x, y - 1);
				}
				else
				{
					if(!h)
					{
						h = true;
						printf("%d ", n * m - cnt * 2);
					}
					printf("%d %d %d %d ", x, y, x, y - 1);
				}
			}
		}
	}
	printf("\n");
	return 0;
}

标签:int,2023,Codeforces,long,++,寒假,ans,len,printf
From: https://www.cnblogs.com/YuukiAsuna/p/17037404.html

相关文章

  • Codeforces Round #266 (Div. 2) C. Number of Ways (dp)
    https://codeforces.com/contest/466/problem/C题目大意:数组a由n个整数组成a[1],a[2],...,a[n]。计算将数组中的所有元素分成三个连续部分的方法,以使每个部分中的元素总和......
  • 2023新年红包,兔年HTML红包页面代码【2023新年快乐_附源码】
    一.新年红包,兔年HTML红包页面1.1资源获取和效果预览1.源码资源获取:https://download.csdn.net/download/weixin_52908342/87373505快速通道:点击跳转下载新年红包,兔年......
  • C语言学生管理系统[2023-01-09]
    C语言学生管理系统[2023-01-09]学生管理系统利用数据结构的单链表的框架实现学生管理系统以下功能要求:1)学生个人信息:姓名、学号、专业、性别、年龄、联系方式、成绩。......
  • SMU Winter 2023 Round #2 (Div.2)(英文)
    A.MediumNumber题目:Giventhreedistinctintegersa,b,andc,findthemediumnumberbetweenallofthem.Themediumnumberisthenumberthatisneitherthe......
  • SMU Winter 2023 Round #1 (Div.2)
    A.不可以,总司令题目:扶苏当上了星战地球舰队的参谋长,但是她不太聪明。人工智能计算出,如果扶苏在一直回答“NO”的话,她在战役中判断完全正确的概率为x%;如果她一直在回答......
  • 2023年最新ios证书申请流程
    做过前端多端开发的朋友们都知道,hbuilderx或apicloud这些开发工具的uniapp框架可以开发ios应用,使用他们的云打包即可。云打包的时候需要一个私钥证书和一个profile文件,这......
  • 2023 好运开年,OpenMLDB 入选 2022 中国技术品牌影响力企业
    导读2023年1月4日,中国技术先锋年度评选|2022中国技术品牌影响力企业榜单正式发布。作为中国领先的新一代开发者社区,SegmentFault思否依托数百万开发者用户数据......
  • Educational Codeforces Round 141 (Rated for Div. 2) A-C题解
    比赛链接A、MakeitBeautiful一种构造方法:按照从大到小的顺序构造,可以发现前缀和永远大于当前值。但是需要特判存在两个最大值的情况。只需要将最小值与第二位交换位置......
  • AtCoder284 D - Happy New Year 2023
    AtCoder284D-HappyNewYear2023[Editorial](Editorial-AtCoderBeginnerContest284)Youaregivenapositiveinteger\(N\).Itisknownthat\(N\)canbe......
  • C语言居民小区水电费管理系统[2023-01-09]
    C语言居民小区水电费管理系统[2023-01-09]居民小区水电费管理系统【问题详述】居民小区水电费管理系统可以对居民小区的用水、用电情况及应交费用进行查询与管理。物业......