当前位置:网站首页>Acwing-116 pilot brother
Acwing-116 pilot brother
2022-07-06 12:35:00 【Want no boat at the bottom of the sea】
The essence of this problem is the same as that of eight digits
First define a state
struct st{
int map[4];// Handle status
int num;// They count
vector<int> s;// route
int a;// ID code
}
About the steps
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define x first
#define y second
using namespace std;
// Defining structure
struct st {
};
st bfs() {
// initialization
queue<st> que;
que.push();
while () {
st t = que.front();
for()
for () {
// Make new elements
if()// End the process when the conditions are met ;
return
}
que.pop()// Delete the head element
}
}
int main() {
// receive data
for (.....) cin >> ...//
// Make the header element
bfs();// Output results
}
The actual code
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define x first
#define y second
using namespace std;
const int N = 5;
int n = 4;
bool jud[1000000];
typedef pair<int, int> two;
struct st {
int map[N][N];
int num;
int a;
vector<two> s;
}st1;
void clone(int a[][N], int b[][N]) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
a[i][j] = b[i][j];
}
}
void change(int x, int y, int mid[][N]) {
for (int i = 1; i <= n; i++)
mid[i][y] = mid[i][y] ^ 1;
for (int i = 1; i <= n; i++)
mid[x][i] = mid[x][i] ^ 1;
mid[x][y] = mid[x][y] ^ 1;
}
int make(int a[][N]) {
int sum = 0, fur = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
if (a[i][j]) sum += 1 << fur++;
else fur++;
}
return sum;
}
st bfs() {
queue<st> que;
que.push(st1);
while (que.size()) {
st t = que.front();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if(t.s.size())
if (i == t.s.back().x&&j == t.s.back().y)
continue;
st mid;
clone(mid.map, t.map);//map
change(i, j, mid.map);
mid.a = make(mid.map);//a
if (!jud[mid.a]) {
jud[mid.a] = true;
mid.num = t.num + 1;//num
mid.s = t.s;//s
mid.s.push_back({ i,j });
que.push(mid);
if (mid.a == 65535) {
cout << mid.num << endl;
return mid;
}
}
}
}
que.pop();
}
}
int main() {
for(int i=1;i<=n;i++)
for (int j = 1; j <= n; j++) {
char a; cin >> a;
if (a == '-') st1.map[i][j] = 1;
else st1.map[i][j] = 0;
}
st1.a = make(st1.map);
jud[st1.a] = 1;
st1.num = 0;
st it = bfs();
for (int i = 0; i < it.s.size(); i++)
cout << it.s[i].x << ' ' << it.s[i].y << endl;
}
边栏推荐
- Pat 1097 duplication on a linked list (25 points)
- Unity3d makes the registration login interface and realizes the scene jump
- JUC forkjoin and completable future
- (五)R语言入门生物信息学——ORF和序列分析
- Easy to use shortcut keys in idea
- Who says that PT online schema change does not lock the table, or deadlock
- ES6 grammar summary -- Part I (basic)
- [Offer18]删除链表的节点
- Esp8266 uses Arduino to connect Alibaba cloud Internet of things
- 如何给Arduino项目添加音乐播放功能
猜你喜欢
C programming exercise
Guided package method in idea
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
dosbox第一次使用
Unity3D,阿里云服务器,平台配置
Arduino JSON data information parsing
JS正则表达式基础知识学习
(4) Data visualization of R language -- matrix chart, histogram, pie chart, scatter chart, linear regression and strip chart
Redis based distributed locks and ultra detailed improvement ideas
2021.11.10 compilation examination
随机推荐
关于Gateway中使用@Controller的问题
[offer78]合并多个有序链表
如何给Arduino项目添加音乐播放功能
记一次云服务器被密码爆破的经历——关小黑屋、改密码、改端口
程序设计大作业:教务管理系统(C语言)
Unity3d camera, the keyboard controls the front and rear left and right up and down movement, and the mouse controls the rotation, zoom in and out
Mysqldump error1066 error solution
[leetcode622] design circular queue
HCIP Day 12
By v$rman_ backup_ job_ Oracle "bug" caused by details
Who says that PT online schema change does not lock the table, or deadlock
VSCode基础配置
(1) Introduction Guide to R language - the first step of data analysis
How to add music playback function to Arduino project
js题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。
基於Redis的分布式ID生成器
Latex learning
1041 Be Unique (20 point(s))(哈希:找第一个出现一次的数)
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
JS变量类型以及常用类型转换