Loading

AtCoder Beginner Contest 397 (OMRON Corporation Programming Contest 2025)



A - Thermometer

题意

思路

模拟

代码

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

const int mxn = 2e5 + 10;

void solve()
{
	double x;
	cin >> x;
	if (x >= 38.0)
	{
		cout << 1 << endl;
	}
	else if (x < 37.5)
	{
		cout << 3 << endl;
	}
	else
	{
		cout << 2 << endl;
	}
}

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

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

	return 0;
}

B - Ticket Gate Log

题意

思路

模拟

代码

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

const int mxn = 2e5 + 10;

void solve()
{
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (i & 1)
		{
			if (s[i] != 'o')
			{
				s.insert(i, "i");
				ans++;
			}
		}
		else
		{
			if (s[i] != 'i')
			{
				s.insert(i, "o");
				ans++;
			}
		}
	}
	if (((int)s.size() & 1))
	{
		ans++;
	}
	cout << ans << endl;
}

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

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

	return 0;
}

C - Variety Split Easy

题意

思路

在遍历的同时记录两边不同的数的种类

代码

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

const int mxn = 2e5 + 10;

void solve()
{
	int n, ans = -1;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	unordered_map<int, int> l, r;
	for (int i = 0; i < n; i++)
	{
		r[a[i]]++;
	}
	for (int i = 0; i < n; i++)
	{
		l[a[i]]++;
		r[a[i]]--;
		if (r[a[i]] == 0)
		{
			r.erase(a[i]);
		}
		ans = max(ans, (int)l.size() + (int)r.size());
	}
	cout << ans << endl;
}

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

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

	return 0;
}

D - Cubes

题意

思路


枚举\(a\),求出\(k\),并且\(k\)要是正整数,同样,\(\sqrt △\)也要是正整数,由于数值太大,需要借助二分来判断,求出的\(\frac {-a + d(\sqrt △)} 2\)同样要是正整数

代码

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

const int mxn = 2e5 + 10;

int f(int x)
{
    if (x < 0)
    {
        return -1;
    }
    int l = 0;
    int r = 1;
    while (r * r < x)
    {
        r *= 2;
    }
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        int sq = mid * mid;
        if (sq == x)
        {
            return mid;
        }
        else if (sq < x)
        {
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    return -1;
}

void solve()
{
    int n;
    cin >> n;
    for (int a = 1; a * a * a <= n; a++)
    {
        int temp = n - a * a * a;
        if (temp < 0)
        {
            continue;
        }
        if (temp % (3 * a) != 0)
        {
            continue;
        }
        int k = temp / (3 * a);
        int dd = a * a + 4 * k;
        int d = f(dd);
        if (d == -1)
        {
            continue;
        }
        if (d < a || ((d - a) & 1))
        {
            continue;
        }
        int y = (d - a) >> 1;
        if (y <= 0)
        {
            continue;
        }
        int x = a + y;
        cout << x << " " << y << endl;
        return;
    }
    cout << -1 << endl;
}

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

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

    return 0;
}

E - Path Decomposition of a Tree

题意

思路

详情见代码

代码

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

const int mxn = 1e6 + 10;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<vector<int>> g(n * k);
	vector<int> sz(n * k, 0); // sz[i] 代表以 i 为根的子树的大小(结点数)
	for (int i = 0; i < n * k - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	if (k == 1)
	{
		cout << "Yes" << endl;
		return;
	}

	function<void(int, int)> dfs = [&](int u, int fa) {
		sz[u] = 1;
		int child = 0;
		for (auto& v : g[u])
		{
			if (v == fa)
			{
				continue;
			}
			dfs(v, u);
			if (sz[v])
			{
				child++;
				sz[u] += sz[v];
			}
		}
		if (sz[u] < k)
		{
			// 路径还没完成,只能充当非连接点
			if (child > 1)
			{
				cout << "No" << endl;
				exit(0);
			}
		}
		else if (sz[u] == k) 
		{
			// 因为要保证“一条”路径,最多两个孩子,此时 u 作连接点
			if (child > 2) 
			{
				cout << "No" << endl;
				exit(0);
			}
			sz[u] = 0; // 恰好一条路径,删除无影响
		}
		else
		{
			cout << "No" << endl;
			exit(0);
		}
	};

	dfs(0, -1);
	cout << "Yes" << 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/abc397

posted @ 2025-03-16 22:02  _SeiI  阅读(77)  评论(0)    收藏  举报