AtCoder Beginner Contest 377



A - Rearranging ABC#

题意#

给长度为3的字符串问是不是ABC

思路#

模拟。

代码#

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

void solve()
{
    int cnt[30] = { 0 };
    for (int i = 0; i < 3; i++)
    {
        char c;
        cin >> c;
        cnt[c - 'A']++;
    }
    if (cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 1)
    {
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << 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 - Avoid Rook Attack#

题意#

8×8的网格,"."表示空,"#"表示有棋子,每个棋子能攻击它所在行和列的所有格子。找出不会被攻击的格子数。

思路#

怎么做都行。

代码#

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

bool r[10], c[10];

void solve()
{
	for (int i = 0; i < 8; i++)
	{
		for (int j = 0; j < 8; j++) 
		{
			char ch;
			ch = getchar();
			if (ch == '#')
			{
				r[i] = c[j] = true;
			}
		}
		getchar();
	}
	int ans = 0;
	for (int i = 0; i < 8; i++) 
	{
		for (int j = 0; j < 8; j++)
		{
			if (!r[i] && !c[j])
			{
				ans++;
			}
		}
	}
	cout << ans << 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 - Avoid Knight Attack#

题意#

n×n的网格,有m个棋子,每个棋子移动如图。找出不会被攻击的格子数。

思路#

set存能攻击的坐标,答案就是n×nset.size()

代码#

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

const int mxn = 2e5 + 5;

int dx[] = { 2, 1, -1, -2, -2, -1,  1,  2 };
int dy[] = { 1, 2,  2,  1, -1, -2, -2, -1 };

int n, m, x, y;
set<pii> vis;

void solve()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        vis.insert({ x,y });
        for (int j = 0; j < 8; j++)
        {
            int tx = x + dx[j];
            int ty = y + dy[j];
            if (tx >= 1 && tx <= n && ty >= 1 && ty <= n)
            {
                vis.insert({ tx, ty });
            }
        }
    }
    cout << n * n - vis.size() << 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 - Many Segments 2#

题意#

给定两个长度为n的序列,以及整数m,求满足以下两个条件的整数对(l,r)的个数:
1lrM
对于每个1in来说,区间[l,r]并不完全包含区间[Li,Ri]

思路#

代码#

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

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> d(m + 1, 1);
    for (int i = 0; i < n; i++)
    {
        int l, r;
        cin >> l >> r;
        d[r] = max(d[r], l + 1);
    }
    for (int r = 1; r <= m; r++)
    {
        d[r] = max(d[r], d[r - 1]);
    }
    int ans = 0;
    for (int r = 1; r <= m; r++)
    {
        ans += r - d[r] + 1;
    }
    cout << ans << endl;
}

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

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

    return 0;
}

E - Permute K times 2#

题意#

给定(1,2,···,n)的排列P=(P1,P2,···,Pn),进行k次操作:使Pi=PPi ( i=1,2,···,n )。求最终序列。

思路#

代码#

点击查看代码



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

posted @   _SeiI  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示