【AtCoder】【Beginner Contest 232】A-D

在这里插入图片描述
题意:给定一个仅包含三个字符的字符串。约定:第一和第三个字符为数字,第二个字符为’x’。计算s[0]*s[1]。
思路:用scanf格式化读取并计算。

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
typedef long long  ll;

void solve()
{
	int a,b;
	scanf("%dx%d",&a,&b);//格式化读入内容
	printf("%d\n",a*b); //计算并输出
}

int main()
{
	ios::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
} 

在这里插入图片描述
题意:是否存在整数k,使得仅包含字母的串s,循环向右移动得到串t。
思路:以(t[0]-a[0]+26)%26为k逐个验证即可。

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
typedef long long  ll;

void solve()
{
	string s,t;
	cin>>s>>t;
	int k = (t[0]-s[0]+26)%26;//k值选取
	for(int i=0;s[i];i++){
		if((t[i]-s[i]+26)%26!=k){//逐个验证
			cout<<"No\n";
			return;
		}
	}
	cout<<"Yes\n";
}

int main()
{
	ios::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
} 

在这里插入图片描述
题意:给定两幅图,判断两图是否同构,即:形态上是否一致。
思路:本来想用离散上的同构判断,但发现代码写起来非常不容易。正解大概是把点进行映射,如果存在一组映射与原数据不冲突即为答案。寻找可能解时使用了全排列,因为如果有解必然是排列的一种,非常的暴力…

#include<bits/stdc++.h>
using namespace std;
const int N = 10+5;
typedef long long  ll;
int a[N][N],b[N][N];

void solve()
{
	int n,m,u,v;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>u>>v;
		u--;v--;
		a[u][v]=a[v][u]=1;
	}
	for(int i=0;i<m;i++){
		cin>>u>>v;
		u--;v--;
		b[u][v]=b[v][u]=1;
	}
	vector<int>arr(n);
	for(int i=0;i<n;++i) arr[i] = i;//初始化一组排列 
	do{
		bool f = true;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(!a[i][j]) continue;//生成与原序列相同的映射 
				f&=b[arr[i]][arr[j]];
			}
		}
		if(f) {//有解则退出 
			cout<<"Yes\n";
			return; 
		}
	} while(next_permutation(arr.begin(),arr.end()));//全排列函数 
	cout<<"No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
} 

在这里插入图片描述
题意:给定包含’.’(表示空)和’#’(表示障碍物)的二维矩阵。问只向下和向右走最远可以走多远?
思路:首先处理好第一行和第一列的边界情况,再用for循环递推所有可以到达的点。其中每一个点到(0,0)点的曼哈顿距离 + 1取max就是结果。

#include<bits/stdc++.h>
using namespace std;
const int N = 100+5;
typedef long long  ll;
char mp[N][N];
bool rch[N][N];

void solve()
{
	int h,w,ans=0;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		cin>>mp[i];
	}
	if(mp[0][0]=='.') rch[0][0]=1;
	for(int i=1;i<w;i++) //第一行 
		if(rch[0][i-1]&&mp[0][i]=='.') rch[0][i]=1;
	for(int i=1;i<h;i++) //第一列 
		if(rch[i-1][0]&&mp[i][0]=='.') rch[i][0]=1;
	//所有可到达的点 
	for(int i=1;i<h;i++){ 
		for(int j=1;j<w;j++){
			if(mp[i][j]=='.'&&(rch[i-1][j]||rch[i][j-1])) rch[i][j]=1;
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<h;j++){
			if(rch[i][j]) ans=max(ans,i+j+1);//曼哈顿距离 + 1
		}
	}
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sophon、

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值