Codeforces Round #625

本文精选了四道算法竞赛题目并提供了详细的代码解答,包括机器人比赛策略、旅行规划中的资源分配、去除字符串中相邻重复字符的优化算法以及导航系统的路径寻找问题。通过对这些题目的深入解析,展示了算法设计和实现的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Contest for Robots

#include <bits/stdc++.h>
using namespace std;
int n,a[maxn],b[maxn];
void solve()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	int temp1=0,temp2=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1&&b[i]==0)
			temp1++;
		else if(a[i]==0&&b[i]==1)
			temp2++;
	}
	if(temp1==0)
		puts("-1");
	else
		printf("%d\n",1+temp2/temp1);
	return;
}
int main()
{
    solve();
    return 0;
}

B. Journey Planning

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pll;
const int inf = 0x3f3f3f3f;
const int maxn=1e6;
ll n,a[maxn],b[maxn],c[maxn];
void solve()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&c[i]);
		ll cha=c[i]-i;
		//cout<<cha<<endl;
		if(cha<0)
		{
			cha*=(-1);
			b[cha]+=c[i];
		}
		else
		{
			a[cha]+=c[i];
		}
	}
	ll maxx=0;
	for(ll i=0;i<maxn;i++)
	{
		maxx=max(maxx,a[i]);
		maxx=max(maxx,b[i]);
	}
	printf("%lld\n",maxx);
	return;
}
int main()
{
    solve();
    return 0;
}

C. Remove Adjacent

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pll;
const int inf = 0x3f3f3f3f;
const int maxn=1e2+10;
int n;
string s;
void solve()
{
	getchar();
	getline(cin,s);
	int ans=0;
	for(char a='z';a>='b';a--)
	{
		for(int j=0;j<n;j++)
		{
			if(s[j]==a)
			{
				int l=j-1;
				while(l>=0&&s[l]==a)
					l--;
				int r=j+1;
				while(l<n&&s[r]==a)
					r++;
				if(l==-1)
					l=0;
				if(r==n)
					r=n-1;
				if(s[l]==a-1||s[r]==a-1)
					s.erase(j,1),ans++,j--;
			}
		}
	}
	cout<<ans<<endl;
	return;
}
int main()
{
	while(~scanf("%d",&n))
    	solve();
    return 0;
}

D. Navigation System
最短路,有空补

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值