IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 数据结构与算法 -> AtCoder Beginner Contest 237(A-D) -> 正文阅读

[数据结构与算法]AtCoder Beginner Contest 237(A-D)


A - Not Overflow

long long范围的数判断是否在int范围内,就可以强制转换

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <numeric>
#include <iomanip>
#include <functional>
using namespace std;
#define lowbit(x) ((x) & -(x))
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;

void solve() {
	long long n;
	cin >> n;
	int m;
	m = n;
	if (m == n) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

int main() {
	IOS1;
	//IOS2;
	int __t = 1;
	//cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*

*/

B - Matrix Transposition

AC代码:

二维,数据大可能会被卡空间的

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <numeric>
#include <iomanip>
#include <functional>
using namespace std;
#define lowbit(x) ((x) & -(x))
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
void solve() {
	int h, w;
	cin >> h >> w;
	int x = max(h, w);
	vector<vector<int>> a(h + 5, vector<int>(w + 5, 0));
	vector<vector<int>> b(w + 5, vector<int>(h + 5, 0));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= w; i++) {
		for (int j = 1; j <= h; j++) {
			b[i][j] = a[j][i];
		}
	}
	for (int i = 1; i <= w; i++) {
		for (int j = 1; j <= h; j++) {
			cout << b[i][j] << " \n"[j == h];
		}
	}
}

int main() {
	IOS1;
	//IOS2;
	int __t = 1;
	//cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*

*/

一维,要看好各个行列关系

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <numeric>
#include <iomanip>
#include <functional>
using namespace std;
#define lowbit(x) ((x) & -(x))
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template <typename T>
inline T
read() {
	T sum = 0, fl = 1;
	int ch = getchar();
	for (; !isdigit(ch); ch = getchar())
		if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
	return sum * fl;
}
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;

void solve() {
	int h, w;
	cin >> h >> w;
	vector<int> a(100010);
	for (int i = 1; i <= h * w; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= w; i++) {
		for (int j = 1; j <= h; j++) {
			cout << a[(j - 1) * w + i] << " \n"[j == h];
		}
	}

}

int main() {
	IOS1;
	//IOS2;
	int __t = 1;
	//cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*

*/

C - kasaka

从开头添加若干个或零个a是否能成为回文字符串

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <numeric>
#include <iomanip>
#include <functional>
using namespace std;
#define lowbit(x) ((x) & -(x))
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;

void solve() {
	string s;
	cin >> s;
	int len = s.length();
	bool ok = true;
	for (int i = 0; i < len / 2; i++) {
		if (s[i] != s[len - 1 - i]) {
			ok = false;
		}
	}
	if (ok) {
		cout << "Yes" << endl;
	}
	else {
		int cnt = 0;
		for (int i = len - 1; i >= 0; i--) {
			if (s[i] == 'a') {
				cnt++;
			}
			else {
				break;
			}
		}
		int cnt1 = 0;
		for (int i = 0; i <= len - 1; i++) {
			if (s[i] == 'a') {
				cnt1++;
			}
			else {
				break;
			}
		}
		int cnt2 = abs(cnt1 - cnt);
		if (cnt1 >= cnt) {
			cout << "No" << endl;
			return;
		}
		string s1 = "";
		for (int i = 1; i <= cnt2; i++) {
			s1 += 'a';
		}
		s1 += s;
		ok = true;
		int len1 = s1.length();
		for (int i = 0; i < len1 / 2; i++) {
			if (s1[i] != s1[len1 - 1 - i]) {
				ok = false;
			}
		}
		if (ok) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

int main() {
	IOS1;
	//IOS2;
	int __t = 1;
	//cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*

*/

D

D - LR insertion

根据题意就是往当前数的左边或者右边添值,乍一看从正面好像不太好弄,那就可以考虑逆着来,数组开个1e6不会太大,直接逆序添加就好了,L就放右边,R就放左边

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <numeric>
#include <iomanip>
#include <functional>
using namespace std;
#define lowbit(x) ((x) & -(x))
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template <typename T>
inline T
read() {
	T sum = 0, fl = 1;
	int ch = getchar();
	for (; !isdigit(ch); ch = getchar())
		if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
	return sum * fl;
}
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;

void solve() {
	int n;
	cin >> n;
	vector<int> a(1000010);
	string s;
	cin >> s;
	int len = s.size();
	int left = 500000 - 1, right = 500000 + 1;
	int x = len - 1;
	a[500000] = len;
	for (int i = len - 1; i >= 0; i--) {
		if (s[i] == 'L') {
			a[right++] = x;
			x--;
		}
		else {
			a[left--] = x;
			x--;
		}
	}
	for (int i = left + 1; i < right; i++) {
		cout << a[i] << " \n"[i == right - 1];
	}
}

int main() {
	IOS1;
	//IOS2;
	int __t = 1;
	//cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*

*/

  数据结构与算法 最新文章
【力扣106】 从中序与后续遍历序列构造二叉
leetcode 322 零钱兑换
哈希的应用:海量数据处理
动态规划|最短Hamilton路径
华为机试_HJ41 称砝码【中等】【menset】【
【C与数据结构】——寒假提高每日练习Day1
基础算法——堆排序
2023王道数据结构线性表--单链表课后习题部
LeetCode 之 反转链表的一部分
【题解】lintcode必刷50题<有效的括号序列
上一篇文章      下一篇文章      查看所有文章
加:2022-02-03 01:23:44  更:2022-02-03 01:26:32 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 17:33:35-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码