Loading

AtCoder Beginner Contest 404



A - Not Found

题意

思路

模拟

代码

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;

const int mxn = 1e6 + 10;

void solve()
{
    string s;
    cin >> s;
    for (int i = 'a'; i <= 'z'; i++)
    {
        if (s.find(i) == s.npos) 
        {
            cout << (char)i << endl;
            return;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int __ = 1;
    //cin >> __;
    while (__--) solve();

    return 0;
}

B - Grid Rotation header

题意

思路

不旋转答案就是二者不同元素的个数,再加上旋转次数即可

代码

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;

const int mxn = 1e6 + 10;

int n;
vector<string> a, b;

void f()
{
	vector<string> t(n, string(n, '.'));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			t[j][n - 1 - i] = a[i][j];
		}
	}
	a = t;
}

void solve()
{
	cin >> n;
	a.resize(n);
	b.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	int ans = 1e18;
	for (int i = 0; i < 4; i++)
	{
		int dif = 0;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (a[i][j] != b[i][j]) dif++;
			}
		}
		ans = min(ans, i + dif);
		f();
	}
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int __ = 1;
	//cin >> __;
	while (__--) solve();

	return 0;
}

C - Cycle Graph?

题意

思路

顶点度数都为\(2\)且连通的简单无向图即循环图

代码

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;

const int mxn = 1e6 + 10;

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> deg(n, 0);
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
		deg[u]++;
		deg[v]++;
	}
	if (n != m)
	{
		cout << "No" << endl;
		return;
	}
	for (auto& i : deg)
	{
		if (i != 2)
		{
			cout << "No" << endl;
			return;
		}
	}
	vector<bool> vis(n, false);
	queue<int> q;
	q.push(0);
	vis[0] = true;
	int cnt = 1;
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (int v : g[u])
		{
			if (!vis[v])
			{
				vis[v] = true;
				q.push(v);
				cnt++;
			}
		}
	}
	cout << (cnt == n ? "Yes" : "No") << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int __ = 1;
	//cin >> __;
	while (__--) solve();

	return 0;
}

D - Goin' to the Zoo

题意

思路

每种动物只需要看\(2\)次,则一个动物园的访问次数最多也为\(2\),暴力枚举所有情况

代码

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;

const int mxn = 1e6 + 10;

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
	}
	vector<vector<int>> a(n);
	for (int i = 0; i < m; i++)
	{
		int k;
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int x;
			cin >> x;
			x--;
			a[x].push_back(i);
		}
	}
	vector<int> p3(n + 1, 1);
	for (int i = 1; i <= n; i++)
	{
		p3[i] = p3[i - 1] * 3;
	}
	int ans = LLONG_MAX;
	for (int i = 0; i < p3[n]; i++)
	{
		vector<int> cnt(m, 0);
		int res = 0;
		for (int j = 0; j < n; j++)
		{
			int t = i / p3[j] % 3; // 该动物园的访问次数
			while (t--)
			{
				for (auto& l : a[j]) cnt[l]++;
				res += c[j];
			}
		}
		if (*min_element(cnt.begin(), cnt.end()) >= 2) ans = min(ans, res);
	}
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int __ = 1;
	//cin >> __;
	while (__--) solve();

	return 0;
}

E - Bowls and Beans

题意

思路

\(f_i = min\{f_{i-c_i},f_{i-c_i+1},···,f_{i-1}\}+1\)

代码

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef pair<int, int> pii;

const int mxn = 1e6 + 10;

void solve()
{
	int n, ans = 0;
	cin >> n;
	vector<int> a(n), c(n), f(n, 0);
	a[0] = c[0] = 0;
	for (int i = 1; i < n; i++)
	{
		cin >> c[i];
	}
	for (int i = 1; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i < n; i++)
	{
		f[i] = 1e18;
		for (int j = i - c[i]; j < i; j++)
		{
			f[i] = min(f[i], f[j] + 1);
		}
		if (a[i])
		{
			ans += f[i];
			// 从其他碗转移来的豆子都可以一次性拿走
			f[i] = 0;
		}
	}
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int __ = 1;
	//cin >> __;
	while (__--) solve();

	return 0;
}


比赛链接 https://atcoder.jp/contests/abc404

posted @ 2025-05-06 21:35  _SeiI  阅读(60)  评论(0)    收藏  举报