Atcoder Beginner Contest 355

A - Who Ate the Cake?

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int A, B;
	cin >> A >> B;
	if (A == B) cout << -1;
	else cout << 6 - A - B;
	return 0;
}

B - Piano 2

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

vector<int> A(105), B(105);

int find(int x) {
	for (auto i : A) {
		if (i == x) return true;
	}
	return false;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vector<int> C;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		C.push_back(A[i]);
	}
	for (int i = 0; i < m; i++) {
		cin >> B[i];
		C.push_back(B[i]);
	}
	sort(C.begin(), C.end());
	for (int i = 0; i < C.size() - 1; i++) {
		int x = C[i], y = C[i + 1];
		if (find(x) && find(y)) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

C - Bingo 2

分别记录每行、每列、对角线中被涂黑的格子数量 \(\rm row[i]\)\(\rm col[i]\)\(d_1\)\(d_2\),每次操作后检查该格子对应的行列对角线的黑格子数是否是 \(N\) 即可。

(一开始的想法是先按题意要求将表格初始化出来,每次操作的时候再将表格对应关键字的地方涂黑,但这样太慢,不如一开始在读入数据的时候就查出行号和列号,将每行和每列、两条对角线上全部统计好后一起查询。)

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

int N, T;
int row[2010], col[2010];

int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);
	cin >> N >> T;
	int d1 = 0, d2 = 0;
	bool flag = false;
	for (int i = 0; i < T; i++) {
		int t;
		cin >> t;
		t--;
		int x = t / N, y = t % N;//快速算出行号和列号
		row[x]++, col[y]++;
		if (x == y) d1 ++;
		if (x + y == N - 1) d2 ++;
		if (row[x] == N || col[y] == N || d1 == N || d2 == N) {
			cout << i + 1 << "\n";
			flag = true;
			break;
		} 
	}
	if (!flag) cout << -1;
	return 0;
}
posted @ 2024-06-06 21:29  胖柚の工作室  阅读(31)  评论(0)    收藏  举报