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
Determine whether it is possible to rearrange the characters in 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
Each square is either empty or has a piece placed on it. The state of the squares is represented by a sequence .
, 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
- Placed on a square in row
- Placed on a square in column
For example, a piece placed on square
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
Each square is either empty or has a piece placed on it. There are
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
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
Here, conditions involving non-existent squares are considered to never be satisfied.
For example, a piece placed on square
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;
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
Find the number of pairs of integers
- For every
, the interval does not completely contain the interval .
对于每一个点,在1到这个点这段区间可以形成的小区间个数就是
一开始我们先把左端点记录到右端点上,然后向右扩散就行,一直取最大的即可
#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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现