AtCoder Beginner Contest 241(Sponsored by Panasonic)(A-D)

A

A - Digit Machine

签到题, 简单的判断a[a[i]]找第三个答案

AC代码:

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
// using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#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;
typedef long long ll;
typedef long long i64;
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 power1(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template<class T>
T power2(T a, int b, T c) {
	T res = 1;
	for (; b; b >>= 1, a = a * a % c) {
		if (b & 1) {
			res = res * a % c;
		}
	}
	return res % c;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
// const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
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)
*/

void solve() {
	vector<int> a(10);
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	int k = 2;
	int ans = a[0];
	int first = 0;
	while (k--) {
		first = a[first];
		ans = a[first];
	}
	cout << ans << endl;
	return;
}
signed main() {
	//IOS1;
	IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	int __t = 1;
	// cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}

B

B - Pasta

map应用,判断有没有需求长度的面条

AC代码:

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
// using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#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;
typedef long long ll;
typedef long long i64;
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 power1(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template<class T>
T power2(T a, int b, T c) {
	T res = 1;
	for (; b; b >>= 1, a = a * a % c) {
		if (b & 1) {
			res = res * a % c;
		}
	}
	return res % c;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
// const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
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)
*/

void solve() {
	int n, m;
	bool ok = true;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> b(m);
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		if (mp[b[i]]) {
			mp[b[i]]--;
		}
		else {
			ok = false;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
	return;
}
signed main() {
	//IOS1;
	IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	int __t = 1;
	// cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}

C

C - Connect 6

六子棋,'#'+'.'=6 && '.'的个数小于等于2,注意要判断八个方向,因为要全部遍历一次就可以了,所以只需要判断右、下、右上和右下,反过来意义相同

AC代码:

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
// using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#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;
typedef long long ll;
typedef long long i64;
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 power1(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template<class T>
T power2(T a, int b, T c) {
	T res = 1;
	for (; b; b >>= 1, a = a * a % c) {
		if (b & 1) {
			res = res * a % c;
		}
	}
	return res % c;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
// const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
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)
*/
vector<int> dx = {0, 1, 1, 1};
vector<int> dy = {1, 0, -1, 1};
void solve() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	bool ok = false;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < 4; k++) {
				if (i + dx[k] * 5 >= 0 && i + dx[k] * 5 < n && j + dy[k] * 5 < n && j + dy[k] * 5 >= 0) {
					int cnt = 0;
					for (int l = 0; l < 6; l++) {
						if (s[i + dx[k] * l][j + dy[k] * l] == '.') {
							cnt++;
						}
					}
					if (cnt <= 2) {
						ok = true;
					}
				}
			}
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return;
}
signed main() {
	//IOS1;
	IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	int __t = 1;
	// cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}

D

D - Sequence Query

实现插入元素以及查询第k大或第k小的操作,根据题意容易想到用multiset以及二分常用的lower_bound和upper_bound对每个操作进行操作

无奈啊,比赛的时候并不会在multiset上用lower_bound和upper_bound,痛失上大分的机会

AC代码:

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
// using i64 = long long;
#define lowbit(x) ((x) & -(x))
#define endl '\n'
#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;
typedef long long ll;
typedef long long i64;
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 power1(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template<class T>
T power2(T a, int b, T c) {
	T res = 1;
	for (; b; b >>= 1, a = a * a % c) {
		if (b & 1) {
			res = res * a % c;
		}
	}
	return res % c;
}
template <typename T>
T Myabs(T a) {
	return a >= 0 ? a : -a;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
// const int mod = 998244353;
const double PI = acos(-1.0);
const double eps = 1e-6;
inline int sgn(double x) {
	return x < -eps ? -1 : x > eps;
}
/*
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)
*/

void solve() {
	int q;
	cin >> q;
	multiset<i64> ms;
	while (q--) {
		int op;
		cin >> op;
		if (op == 1) {
			i64 x;
			cin >> x;
			ms.insert(x);
		}
		else if (op == 2) {
			i64 x, k;
			cin >> x >> k;
			auto it = ms.upper_bound(x);
			bool ok = true;
			for (int i = 0; i < k; i++) {
				if (it == ms.begin()) {
					ok = false;
					break;
				}
				it--;
			}
			
			if (ok) {
				cout << *it << endl;
			}
			else {
				cout << -1 << endl;
			}
		}
		else {
			i64 x, k;
			cin >> x >> k;
			bool ok = true;
			auto it = ms.lower_bound(x);
			for (int i = 0; i < k - 1; i++) {
				if (it == ms.end()) {
					ok = false;
					break;
				}
				it++;
			}
			if (it == ms.end()) {
				ok = false;
			}
			if (ok) {
				cout << *it << endl;
			}
			else {
				cout << -1 << endl;
			}
		}
	}
	return;
}
signed main() {
	//IOS1;
	IOS2;
#ifdef ONLINE_JUDGE
#else
	freopen("in.txt", "r", stdin);
#endif
	int __t = 1;
	// cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值