AtCoder Beginner Contest 384



A - aaaadaa#

题意#

给定长为n的字符串s,和两个字符c1c2,把s中不是c1的字符替换成c2

思路#

模拟

代码#

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

const int mxn = 1e6 + 5;

	

void solve()
{
	int n;
	char a, b;
	string s;
	cin >> n >> a >> b >> s;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != a)
		{
			s[i] = b;
		}
	}
	cout << s << endl;
}

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

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

	return 0;
}

B - ARC Division#

题意#

n场比赛,已知初始分数r,每场比赛有diai两个属性,分别表示分区与分数变动。当前分数处在对应分区分数才改变,否则不变。分区1[1600,2799],分区2[1200,2399]。求最终分数

思路#

模拟

代码#

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

const int mxn = 1e6 + 5;

	

void solve()
{
	int n, r;
	cin >> n >> r;
	for (int i = 0; i < n; i++)
	{
		int d, a;
		cin >> d >> a;
		if (d == 1 && r >= 1600 && r <= 2799)
		{
			r += a;
		}
		else if (d == 2 && r >= 1200 && r <= 2399)
		{
			r += a;
		}
	}
	cout << r << endl;
}

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

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

	return 0;
}

C - Perfect Standings#

题意#

总共5个题ABCDE,给定每个题对应的分数abcde,输出所有31种出题情况分高的在前,分一样按出题的字典序排。

思路#

求出每种情况的分数,带上字符串排序。

代码#

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

const int mxn = 1e6 + 5;

int a, b, c, d, e;
string s = "ABCDE";
vector<pii> ans;

bool cmp(const pii& a, const pii& b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first > b.first;
}

void solve()
{
    vector<int> SC(5);
    for (int i = 0; i < 5; i++)
    {
        cin >> SC[i];
    }
    for (int i = 1; i < (1LL << 5); i++) // 每个题都有出跟不出两种情况,没有一个题都没出的情况,所以是<2^5
    {
        int sc = 0;
        string name = "";
        for (int j = 0; j < 5; j++)
        {
            if (i & (1LL << j))
            {
                name.push_back(s[j]);
                sc += SC[j];
            }
        }
        ans.push_back({ sc, name });
    }
    sort(ans.begin(), ans.end(), cmp);
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i].second << endl;
    }
}

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

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

    return 0;
}

D - Repeated Sequence#

题意#

给定周期为n的无穷序列的前n项,问该无穷序列是否存在连续子序列,使得这个子序列之和等于s

思路#

因为是连续子序列,很容易想到前缀和,但是这个序列有周期,所以可能出现s=a4+a5(a1)+a6(a2)(假设周期为4),所以至少需要2个周期长度的前缀和。并且只需要看s(sum是一个周期之和),即剩下的这部分是否与一个区间和相等即可。由于处理所有区间和需要O(n2)的复杂度(T了),所以将pre[i]pre[j]=s转化为pre[j]=pre[i]s,用set来维护,从而简化到O(n log n)

代码#

点击查看代码
#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve()
{
    int n, s;
    cin >> n >> s;
    vector<int> a(n + 1), pre(2 * (n + 1));
    set<int> st;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    for (int i = n + 1; i <= 2 * n; i++)
    {
        pre[i] = pre[i - 1] + a[i - n];
    }
    st.insert(0);
    s %= pre[n];
    if (!s)
    {
        cout << "Yes" << endl;
        return;
    }
    for (int i = 1; i <= 2 * n; i++)
    {
        if (st.count(pre[i] - s))
        {
            cout << "Yes" << endl;
            return;
        }
        st.insert(pre[i]);
    }
    cout << "No" << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


E - Takahashi is Slime 2#

题意#

给定h×w的网格,(i,j)有一团强度为Si,j的粘液,最初有一团粘液在(p,q),他会吸收与之相邻且强度严格小于它的粘液。求最后的粘液强度。

思路#

BFS但需要用小根堆,每次取最小的吸收,当没有可以吸收(队头强度大于等于当前强度)或全部吸收完时结束。

代码#

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

const int mxn = 5e2 + 5;

struct node
{
	int x, y, w;
	bool operator < (const node& a)const
	{
		return w > a.w;
	}
};

int h, w, X, a, b, now;
int mp[mxn][mxn];
bool vis[mxn][mxn];
int dx[] = { 1,-1,0,0 };
int dy[] = { 0,0,1,-1 };

void solve()
{
	cin >> h >> w >> X >> a >> b;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cin >> mp[i][j];
		}
	}
	priority_queue<node> q;
	q.push({ a,b,mp[a][b] });
	vis[a][b] = true;
	bool f = false;
	while (q.size())
	{
		int x = q.top().x;
		int y = q.top().y;
		if ((int128)mp[x][y] * X >= now&& f) // 注意这里直接乘会爆,要不就int128,要不就直接除也能过
		{
			break;
		}
		f = true;
		now += q.top().w;
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int tx = x + dx[i];
			int ty = y + dy[i];
			if (tx > 0 && ty > 0 && tx <= h && ty <= w && !vis[tx][ty])
			{
				q.push({ tx,ty,mp[tx][ty] });
				vis[tx][ty] = true;
			}	
		}
	}
	cout << now << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	solve();
	return 0;
}



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

posted @   _SeiI  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示