蓝桥冲刺31天打卡—Day20

目录

1.🌟七星填数

📕题目描述:

☀️思路:

✏️代码 : 

2.🌟旋转

📕题目描述:

☀️思路:

✏️代码 : 

3.🌟迷宫与陷阱

📕题目描述:

☀️思路:

✏️代码 : 


1.🌟七星填数

📕题目描述

☀️思路:

全排列后进行判断,注意:判断时用不等于判断,减少代码量

✏️代码 : 

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[12] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 12, 13};
bool check() {

	int num1 = a[0] + a[1] + a[2] + a[3];
	int num2 = 6 + a[1] + a[4] + 14;
	int num3 = 6 + a[2] + a[5] + 11;
	int num4 = a[3] + a[5] + a[7] + a[10];
	int num5 = a[8] + a[9] + a[7] + 11;
	int num6 = a[6] + a[10] + a[8] + 14;
	int num7 = a[0] + a[4] + a[6] + a[9];
	if (num1 != num2)
		return 0;
	if (num2 != num3)
		return 0;
	if (num3 != num4)
		return 0;
	if (num4 != num5)
		return 0;
	if (num5 != num6)
		return 0;
	if (num6 != num7)
		return 0;
	return 1;


}
int main() {
	do {
		if (check()) {
			cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;
			return 0;

		}

	} while (next_permutation(a, a + 11));

	return 0;
}

2.🌟旋转

📕题目描述

 

 

 

☀️思路:

第一行交换到倒数第一列,第二行交换到倒数第二列........ 从此可看出

新矩阵和原矩阵行列之间的关系,再进行输出

✏️代码 : 

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110 ;
int n, m;
int a[N][N];
int b[N][N];
//一行到最后一列
//二行到倒数第二列
int main() {

	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i][j];


	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			b[i][j] = a[n - 1 - j][i];
			cout << b[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

3.🌟迷宫与陷阱

📕题目描述

 

☀️思路:

bfs题,注意:当捡到无敌药水时,除了墙不能走外都能走,包括已经走过的点。也就是说,捡到药水后可以无视vis标记数组,走除了墙以外的最短路

✏️代码 : 

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<queue>
using namespace std;
const int N = 1000 ;
struct node {
	int x;
	int y;
	int st;//无敌状态剩余步数
	int d;//步数
};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
char mp[N][N];
bool vis[N][N];
int n;
int k;//无敌状态持续时间k
bool check(int x, int y) {
	if (x < 1 || y < 1 || x > n || y > n) return false; //越界
	return true;
}
//无敌时忽略vis[]
int  bfs(int x, int y) {

	queue<node>q;
	q.push({x, y, 0, 0});
	vis[x][y] = 1;

	while (q.size()) {
		node t = q.front();
		q.pop();
		if (t.x == n && t.y == n) return t.d; //终点

		for (int i = 0; i < 4; i++) {
			int fx = t.x + dx[i], fy = t.y + dy[i];
			if (mp[fx][fy] == '#') continue; //墙
			if (!check(fx, fy)) continue; //越界

			if (mp[fx][fy] == '%') {
				q.push({fx, fy, k, t.d + 1});
				mp[fx][fy] = '.';
				vis[fx][fy] = 1;
			} else if (mp[fx][fy] == '.') {
				if (t.st > 0) { //无敌
					q.push({fx, fy, t.st - 1, t.d + 1});
					vis[fx][fy] = 1;
				} else {
					if (!vis[fx][fy]) {
						q.push({fx, fy, t.st, t.d + 1});
						vis[fx][fy] = 1;
					}
				}
			} else if (mp[fx][fy] == 'X') {
				if (t.st > 0) { //无敌时才能走陷阱
					q.push({fx, fy, t.st - 1, t.d + 1});
					vis[fx][fy] = 1;
				}
			}
		}
	}
	return -1;
}
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> mp[i][j];
		}
	}

	cout << bfs(1, 1);
	return 0;
}

补上昨天的打卡,还是有两题不会,后续补充

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

月色美兮

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

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

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

打赏作者

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

抵扣说明:

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

余额充值