2024年睿抗机器人开发者大赛(RAICOM)CAIP-编程技能赛-本科组省赛

RC-u1 热҈热҈热҈

暴力

#include<iostream>
using namespace std;
signed main()
{
    cin>>n>>m;
    int cnt=0,ans=0;
    while(n--){
		int a;
		cin>>a;
		if(a>34){
			if(m!=4)cnt++;
			else ans++;
		}
		m=m%7+1;
	}
	cout<<cnt<<" "<<ans<<"\n";
	return 0;
}

RC-u2 谁进线下了?

模拟

#include<iostream>
#include<deque>
using namespace std;
const int N = 2e5 + 10;
int d[N];
int v[30]={0,12,9,7,5,4,3,3,2,2,2,1,1,1,1,1};
int n,m;
signed main()
{
	cin>>n;
	while(n--){
		for(int i=1;i<=20;i++){
			int p,k;
			cin>>p>>k;
			d[i]+=v[p]+k;
		}
	}
	for(int i=1;i<=20;i++){
		cout<<i<<" "<<d[i]<<"\n";
	}
	return 0;
}


RC-u3 暖炉与水豚

模拟

#include<iostream>
#include<set>
using namespace std;
#define int long long
typedef pair<int,int>PII;
char c[1100][1100];
//处理
void mv(int x,int y,char d){
	for(int i=-1;i<=1;i++){
		for(int j=-1;j<=1;j++){
			if(c[i+x][j+y]==d)c[i+x][j+y]='x';
		}
	}
}
//查找
bool find(int x,int y){
		for(int i=-1;i<=1;i++){
			for(int j=-1;j<=1;j++){
				if(c[x+i][y+j]=='w')return true;
			}
		}
		return false;
}
signed main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%s",c[i]+1);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(c[i][j]=='m')mv(i,j,'w');
			if(c[i][j]=='c')mv(i,j,'.');
		}
	}
	set<pair<int,int>>s;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(c[i][j]=='.' and find(i,j))s.insert({i,j});
		}
	}
    if(s.size()==0){
        puts("Too cold!");
        return 0;
    }
	for(auto [x,y]:s)cout<<x<<" "<<y<<"\n";
	return 0;
}

RC-u4 章鱼图的判断

跑环判断注意环中环

样例

1

8 9

1 2

2 3

3 4

4 5

5 6

6 7

7 1

7 8

8 2

//代码一(连通分量)
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
vector<int>v[N];
int tia[N],low[N],timetie;
void trajan(int a,int fa)
{
    low[a]=tia[a]=++timetie;
    for(auto it:v[a])
    {
        if(!tia[it])
        {
            trajan(it,a);
            low[a]=min(low[a],low[it]);
        }
        else if(it!=fa)low[a]=min(low[a],low[it]);
    }
}
int ma=0;
bool st[N];
bool bfs(int a){
	queue<int>q;
	q.push(a);
	int cnt=0,re=1;
    while(q.size()){
		auto it=q.front();
		q.pop();
		int ans=0;
        if(low[it]!=tia[it])re++;
		for(auto t:v[it])
		{
			if(st[t])continue;
			st[t]=1;
			q.push(t);
			if(low[t]!=tia[t])ans++;

		}
		if(ans>2)return false;
		else if(ans==2)cnt++;
	}
	if(cnt==1)ma=re;
	return cnt==1;
}
void sove()
{
int n,m;
cin>>n>>m;
timetie=0;
for(int i=1;i<=n;i++)v[i].clear(),low[i]=tia[i]=st[i]=0;
while(m--)
{
    int a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
}
int ans=0;
for(int i=1;i<=n;i++)
{
    if(!tia[i])trajan(i,-1),ans+=bfs(i);
}
if(ans==1)cout<<"Yes "<<ma<<"\n";
else cout<<"No "<<ans<<"\n";
}
int main()
{
	int t;
	cin>>t;
	while(t--)sove();
}

如果不会连通分量其实可以使用图论基础知识给过了

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef pair<int,int>PII;
vector<int>h[N];
//st 0:没有走过,1代表通过拓扑图跑掉了(不在环中的点),2代表环中点
//ss代表当前点下边有多少个环,rec代表当前连通图中环上点的个数,sum代表某个章鱼图中环上点个数
int d[N],st[N],sum=0,rec=0,ss[N];
//bfs跑连通图,统计连通图中环的个数
int bfs(int a,int fa){
	st[a]=2;
	rec++;
	ss[a]=0;
	//s代表这点连通图的个数
	for(auto it:h[a])
	{
		if(it==fa)continue;
		if(st[it]==2 and !ss[it])ss[a]++;
		else if(st[it]==2)ss[a]+=ss[it]-1;
		if(!st[it]) {
			ss[a]+=bfs(it,a);
		} 
	}
//	cout<<a<<" "<<ss[a]<<"??\n";
	return ss[a];
}
//统计图上点
void sove()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)h[i].clear(),st[i]=ss[i]=0;
	while(m--){
		int a,b;
		cin>>a>>b;
		h[a].push_back(b);
		h[b].push_back(a);
	}
//拓扑跑掉非环上点
{
	queue<int>q;
	for(int i=1;i<=n;i++){d[i]=h[i].size();
	if(d[i]==1)q.push(i);
	}
	while(q.size()){
		auto it=q.front();
		q.pop();
		if(st[it])continue;
		st[it]=1;
		for(auto t:h[it])if(!st[t] and --d[t]==1)q.push(t);
	}
}
	//ans代表章鱼图的个数
	int ans=0;
//循环遍历跑环上点
	for(int i=1;i<=n;i++)
	{
		if(!st[i]){
			rec=0;
			int cnt=bfs(i,-1);
		//	cout<<cnt<<"\n";
			if(cnt==1){
				ans++;
				sum=rec;
			}
		}
	}
	if(ans==1)printf("Yes %d\n",sum);
	else printf("No %d\n",ans);
}
signed main()
{
	int t;
	cin>>t;
	while(t--)sove();
	return 0;
}

RC-u5 工作安排

dp

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
struct G{
	int t,d,p;
};
int s[100000];
void sove()
{
	int n;
	cin>>n;
	vector<G>v(n);
	int ma=0;
	for(auto &[t,d,p]:v)cin>>t>>d>>p,ma=max(ma,d);
//按照结束时间排序
    sort(v.begin(),v.end(),[&](auto a,auto b){
		return a.d<b.d;
	});
	for(int i=0;i<=ma;i++)s[i]=0;
	ma=0;
	for(auto &[t,d,p]:v){
		for(int i=d;i>=t;i--)s[i]=max(s[i],s[i-t]+p),ma=max(ma,s[i]);
	}
	cout<<ma<<"\n";
}
signed main()
{
	int t;
	cin>>t;
	while(t--)sove();
	return 0;
}

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值