首页 > 其他分享 >2022/03/01刷题

2022/03/01刷题

时间:2023-03-01 22:56:33浏览次数:52  
标签:03 01 cout int res long 2022 include define

B. Prinzessin der Verurteilung

链接

B. Prinzessin der Verurteilung

直接暴力枚举所有情况,可以发现最多最多枚举到3个字符就可以通过

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 2 * 100005;


signed main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) {
		int n;
		string s;
		cin >> n >> s;
		string temp;
		for (int i = 'a'; i <= 'z'; i++) {//枚举1个字母,找到退出
			temp = "";
			temp = temp + (char)i;
			if (strstr(s.c_str(), temp.c_str()) == NULL) {
				goto out;


			}

		}


		for (int i = 'a'; i <= 'z'; i++) {

			for (int j = 'a'; j <= 'z'; j++) {//枚举2个字母,找到退出
				temp = "";
				temp = temp + (char)i;
				temp = temp + (char)j;
				if (strstr(s.c_str(), temp.c_str()) == NULL) {
					goto out;

				}

			}
		}
		for (int i = 'a'; i <= 'z'; i++) {//枚举3个字母,找到退出

			for (int j = 'a'; j <= 'z'; j++) {
				for (int k = 'a'; k <= 'z'; k++) {
					//TODO

					temp = "";
					temp = temp + (char)i;
					temp = temp + (char)j;
					temp = temp + (char)k;

					if (strstr(s.c_str(), temp.c_str()) == NULL) {
						goto out;

					}
				}

			}
		}
out:
		cout << temp << '\n';//打印结果





	}



	return 0;
}

A. Ahahahahahahahaha

链接

A. Ahahahahahahahaha

这个题很有规律,可以发现一种通解,如果1的数数量大于0的数量的话,此时1的数量肯定是大于n/2的.如果n是偶数的话,直接打印这些1,如果1的数量为奇数,让1的个数减去1,再打印出来.如果0的数量大于1的数量直接打印出说有的0,就可以了

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 1005;

int a[N];
int st[3];
signed main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		memset(st, 0, sizeof st);//初始化

		for (int i = 0; i < n; i++) {
			cin >> a[i];
			st[a[i]]++;//统计1和0的数量
		}
		if (st[1] > st[0]) {//1的数量大于0的数量
			if (st[1] % 2 == 1) {//数量为奇数打印st[1]-1个
				cout << st[1] - 1 << '\n';
				for (int i = 0; i < st[1] - 1; i++) {
					cout << 1 << ' ';
				}
			} else {//偶数直接打印出来个
				cout << st[1] << '\n';
				for (int i = 0; i < st[1]; i++) {
					cout << 1 << ' ';
				}

			}
			cout << '\n';
		} else {//0比较的的话 直接打印全部的0
			cout << st[0] << '\n';

			for (int i = 0; i < st[0]; i++) {
				cout << 0 << ' ';
			}
			cout << '\n';



		}





	}



	return 0;
}

B. Bear and Finding Criminals

链接

B. Bear and Finding Criminals

这个题的数据范围不大直接模拟枚举

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 210;

int a[N];

signed main () {
	ios::sync_with_stdio(false);
	int n = 0, k = 0;
	cin >> n >> k;
	int res = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];//读入数组
	}
	if (a[k] == 1) {//看一些索引为k的是什么是1直接让res加1
		res++;
	}
	for (int i = 1;; i++) {
		if (k + i <= n && k - i >= 1) {//两个索引都有效
			if (a[k + i] == 1 && a[k - i] == 1) {
				res = res + 2;//两个都是1直接加2,只有一个是1不加
			}

		} else if (k + i > n && k - i < 1) {//没有索引有效直接退出
			break;
		} else {//只有一个索引有效
			if (k + i <= n && a[k + i] == 1) {//两边有一个是1直接加1
				res++;

			} else if (k - i >= 1 && a[k - i] == 1) {
				res++;

			}


		}




	}
	cout << res << '\n';








	return 0;
}

D. Line

链接

D. Line

这个题也很有意思,很明显以中间分割左边部分看向右边是值最大的,右边的部分看向左边是之和是最大的.所以我们看左边部分不为R的然后计算变成R之后比原来的L多了多少值,右边部分也以此类推,都放入一个数组中最后对数组排序,打印结果

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 210;

int a[N];
bool cmp (int a, int b) {
	return a > b;
}
signed main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) {
		int n;
		string s;
		cin >> n;
		cin >> s;
		int res = 0;
		vector<int> cnt;
		for (int i = 0; i < n / 2; i++) {
			if (s[i] == 'L') {//如果左边部分为L
				res = res + i;//先让res加上i
				cnt.push_back(abs((n - i - 1) - i));//计算变成R之后比L多多少值,加入数组
			} else {
				res = res + n - i - 1;//如果是R的话加上当前这个位置的值
			}

		}
		for (int i = n / 2; i < n; i++) {//遍历右半部分
			if (s[i] == 'R') {//如果为R的话
				res = res + (n - i - 1);//先将res的值加上
				cnt.push_back(abs(i - (n - i - 1)));//将变成L的差值入队列
			} else {
				res = res + i;//如果为L直接加上当前的值
			}
		}
		sort(cnt.begin(), cnt.end(), cmp);//排序
		for (int i = 1; i <= n; i++) {
			if (i - 1 < cnt.size()) {//看一下当前的下标有没有超过cnt.size
				cout << res + cnt[i - 1] << ' ';//没有直接输出加上当前的差值
				res = res + cnt[i - 1];//加上差值
			} else {
				cout << res << ' ';//大于cnt.size之后每次输出最后的值



			}


		}
		cout << '\n';




	}






	return 0;
}

B. Cat Cycle

链接

B. Cat Cycle

这个题比较好像但是不好写,看了别人的题解才会的

如果是偶数两个猫不会相遇

如果是奇数的话,加上b猫跳过a猫多少次

然后计算一下就可以了

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 100008;
int fa[N];
int size1[N];
int n, m;

signed main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		k--;//因为在第1个小时会站在原地,先k--
		int res = 0;
		if (n % 2 == 0) { //永远不会相遇
			res = k % n + 1; //到达终点


			cout << res << '\n';
		} else {
			int t = k / (n / 2);//n/2步跳过一次,一共跳过k次
			k = k + t;//将k加上t
			int res = 0;
			res = k % n + 1;//算出最后的位置
			cout << res << '\n';


		}





	}


	return 0;
}

C. Wrong Addition

链接

C. Wrong Addition

这个题是一个很感觉是一个很复杂的模拟题,写了好久都不对,具体看代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;
const int N = 2 * 100005;

signed main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--) {
		int a, s;
		cin >> a >> s;
		vector <int> b;
		while (s != 0) {//s为0退出循环
			int x = a % 10;
			int y = s % 10;
			if (x <= y) { //y比较大
				b.push_back(y - x);//直接将差值加入数组


			} else {//x比较大的话
				s = s / 10;
				y = y + (s % 10) * 10;//y向前借一位
				if (x < y && y <= 18 && y >= 10) {//判断y是不是合法y应该是大于x并且不可能大于18并且不可能小于10
					b.push_back(y - x);//满足加入数组
				} else {//如果不满足打印-1
					cout << -1 << '\n';
					goto out;
				}
			}
			a = a / 10;
			s = s / 10;


		}
		if (a != 0) {//如果b都枚举完了,a还不为0的话,因为a为0才对
			cout << -1 << '\n';//打印-1
			goto out;


		} else {
			while (b.back() == 0) {//去除前导零
				b.pop_back();
			}
			for (int i = b.size() - 1; i >= 0; i--) {
				cout << b[i];//倒着输出
			}
			cout << '\n';

		}
out:
		continue;




	}












	return 0;
}

标签:03,01,cout,int,res,long,2022,include,define
From: https://www.cnblogs.com/harper886/p/17170205.html

相关文章

  • Day01
    Markdowen学习标题:二级标题字体HelloWorld?HelloWorld?HelloWorld?HelloWorld?l两边波浪号引用选择狂神说Jawa分割线图片超链[dianjitiaozhuan](博客园......
  • day03
    Jawa三大版本writeonce,runanywhere基于JVM虚拟机JAWASE标准版(桌面程序,控制台开发)JAWAME嵌入式开发(手机小家电),目前无人应用jawaeeE企业级开发(Web端,服务器开发)J......
  • 路飞项目 day03 前端配置、后台主页、项目依赖问题
    一、路飞项目前端配置1.先删除一些不要的​ 删除多余的组件,只要app和首页组件​ 然后改一下组件的内部代码-App.vue中______________<template><divid="app"><rou......
  • django项目初创建报错TypeError: unsupported operand type(s) for /: 'str' and 'str
     解决办法: 'DIRS':[os.path.join(BASE_DIR,'templates')],   ......
  • 2018GPLT (天梯赛训练03-01)
    2018GPLT (天梯赛训练03-01)1.天梯赛座位分配这题在网上都没找到篇靠谱的解答很多都是错的(可能但凡会点编程的人都不会被这题卡住了吧)(悲)从我的好朋友毛的程序我觉得......
  • 3月01日课后总结
    3/01课后总结装饰器装饰器简易版本defouter(func_name):#func_name=indexdefget_time():#1.在函数执行之前,要记录一下此时的时间sta......
  • day01(2023.3.1)
    1、了解了Java运行机制jdk和jre和jvm的区别 2、下载安装jdk然后配置环境变量 并验证是否成功(1)百度收搜Jdk8(推荐),找到下载地址。(2)同意协议,下载电脑对应的版本。......
  • 403. 青蛙过河 (Hard)
    问题描述403.青蛙过河(Hard)一只青蛙想要过河。假定河流被等分为若干个单元格,并且在每一个单元格内都有可能放有一块石子(也有可能没有)。青蛙可以跳上石子,但是不可以......
  • C语言员工信息管理系统[2023-03-01]
    C语言员工信息管理系统[2023-03-01]物联网工程专业程序设计基础课程设计员工信息管理系统学院(系):信息与通信工程学院专业:物联网工程学生姓名:学......
  • SRTP_Log_20230301
    WorkingContent:1.第一个是参数1,第二个是噪声1,第三个是参数2,第四个是噪声2如果没加噪声(以下情况),所以照理来说噪声1和噪声2的量级应该分别比参数1和参数2小得多,现在看......