TOYOTA SYSTEMS Programming Contest 2024(AtCoder Beginner Contest 377)A-D题解

TOYOTA SYSTEMS Programming Contest 2024(AtCoder Beginner Contest 377)

A - Rearranging ABC

Problem Statement

You are given a string S of length 3 consisting of uppercase English letters.

Determine whether it is possible to rearrange the characters in S to make it match the string ABC.

根据题意求解即可

#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define TLE (double)clock() / CLOCKS_PER_SEC <= 0.95
#define int long long
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e6 + 5, M = 1e6 + 5, S = 1e6 + 5, inf = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
int a, b, x;
map<char,int>mp;
void solve()
{
    string s;
	cin>>s;
	 for(auto i:s){
	 	mp[i]=1;
	 }
	 if(mp['A']==0){
	 	cout<<"No"<<endl;
	 	return;
	 }
	 	 if(mp['C']==0){
	 	cout<<"No"<<endl;
	 	return;
	 }
	 	 if(mp['B']==0){
	 	cout<<"No"<<endl;
	 	return;
	 }
	 cout<<"Yes"<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve();
    }
    return 0;
}

B - Avoid Rook Attack

Problem Statement

There is a grid of 64 squares with 8 rows and 8 columns. Let (i,j) denote the square at the i-th row from the top (1i8) and j-th column from the left (1j8).

Each square is either empty or has a piece placed on it. The state of the squares is represented by a sequence (S1,S2,S3,,S8) of 8 strings of length 8. Square (i,j) (1i8,1j8) is empty if the j-th character of Si is ., and has a piece if it is #.

You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.

A piece placed on square (i,j) can capture pieces that satisfy either of the following conditions:

  • Placed on a square in row i
  • Placed on a square in column j

For example, a piece placed on square (4,4) can capture pieces placed on the squares shown in blue in the following figure:

How many squares can you place your piece on?

开两个数组,记录可以吃到的行和列,然后遍历找出行和列都不能被吃到的点即可

#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define TLE (double)clock() / CLOCKS_PER_SEC <= 0.95
#define int long long
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e6 + 5, M = 1e6 + 5, S = 1e6 + 5, inf = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
int a, b, x;
char arr[10][10];
int vis1[10];
int vis2[10];
void solve()
{
	for(int i=1;i<=8;i++){
		for(int j=1;j<=8;j++){
			cin>>arr[i][j];
			if(arr[i][j]=='#'){
				vis1[i]=1;
				vis2[j]=1;
			}
		}
	} 
	int ans = 0;
		for(int i=1;i<=8;i++){
		for(int j=1;j<=8;j++){
			if(vis1[i]==0&&vis2[j]==0){
				ans++;

			}
		}
	} 
	cout<<ans<<endl;

}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve();
    }
    return 0;
}

C - Avoid Knight Attack

Problem Statement

There is a grid of N2 squares with N rows and N columns. Let (i,j) denote the square at the i-th row from the top (1iN) and j-th column from the left (1jN).

Each square is either empty or has a piece placed on it. There are M pieces placed on the grid, and the k-th (1kM) piece is placed on square (ak,bk).

You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.

A piece placed on square (i,j) can capture pieces that satisfy any of the following conditions:

  • Placed on square (i+2,j+1)
  • Placed on square (i+1,j+2)
  • Placed on square (i1,j+2)
  • Placed on square (i2,j+1)
  • Placed on square (i2,j1)
  • Placed on square (i1,j2)
  • Placed on square (i+1,j2)
  • Placed on square (i+2,j1)

Here, conditions involving non-existent squares are considered to never be satisfied.

For example, a piece placed on square (4,4) can capture pieces placed on the squares shown in blue in the following figure:

How many squares can you place your piece on?

一共有n2个格子。把题目中给的棋子和它们能吃到的点全部扔到一个set里,输出n2set.size()即可

#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define TLE (double)clock() / CLOCKS_PER_SEC <= 0.95
#define int long long
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int N = 1e6 + 5, M = 1e6 + 5, S = 1e6 + 5, inf = 0x3f3f3f3f3f3f3f3f, mod = 998244353;

void solve()
{
	int n,m;
	cin>>n>>m;
	set<pii>mp;
	while(m--){
		int i,j;
		cin>>i>>j;
		pii temp  ={i,j};
		mp.emplace(temp);
		int x1,y1;
		x1 = i+2,y1=j+1;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i+1,y1=j+2;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i-1,y1=j+2;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i-2,y1=j+1;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i-2,y1=j-1;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i-1,y1=j-2;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i+1,y1=j-2;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
		
		x1=i+2,y1=j-1;
		if(x1>=1&&x1<=n&&y1>=1&&y1<=n){
			pii temp  ={x1,y1};
		mp.emplace(temp);
		}
	}
    int g = mp.size();
	cout<<n*n-g<<endl;
	

}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    // cin >> T;
    for (int o = 1; o <= T; o++)
    {
        solve();
    }
    return 0;
}

D - Many Segments 2

Problem Statement

You are given two sequences of positive integers of length N, L=(L1,L2,,LN) and R=(R1,R2,,RN), and an integer M.

Find the number of pairs of integers (l,r) that satisfy both of the following conditions:

  • 1lrM
  • For every 1iN, the interval [l,r] does not completely contain the interval [Li,Ri].

对于每一个点,在1到这个点这段区间可以形成的小区间个数就是 i(题意中自己也可以,所以要加上自己)。如果这段区间中包含了一个题目中给出的不能包含的区间,那么形成的子区间数量就是 i(l+1)+1 ( l 是不能包含的那个区间的左端点)。假设中间包含了多个不能包含的区间,那么应该取左端点最大的那一个

一开始我们先把左端点记录到右端点上,然后向右扩散就行,一直取最大的即可

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int n, m; 
    cin >> n >> m;
    vector<int>l(n+1);
    vector<int>r(n+1);
    vector<int>ans(m+1,1);
    for(int i=1;i<=n;i++){
        cin>>l[i]>>r[i];
        ans[r[i]] = max(ans[r[i]],l[i]+1);
    }
    for(int i=1;i<=m;i++){//向右扩散
    ans[i] = max(ans[i],ans[i-1]);

    }
    int cnt = 0;
    for(int i=1;i<=m;i++){
        cnt+=(i-ans[i]+1);
    }
    cout<<cnt<<endl;
}

posted @   haihaichibaola  阅读(130)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示