CSL的校园卡

思路:

bfs,用状压表示走过的区域,然后和x1,y1,x2,y2构成所有的状态,然后标记一下就可以了

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head bool vis[(<<) + ][][][][];
int dir[][] = {, , , , , -, -, };
char s[][];
int n, m;
struct node {
int x1, y1, x2, y2, dis, st;
};
int get(int x, int y) {
return (x-)*m + y - ;
}
int bfs() {
queue<node> q;
int st = ;
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
if(s[i][j] == 'S' || s[i][j] == 'X') st |= <<get(i, j);
}
}
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
if(s[i][j] == 'S') {
q.push(node{i, j, i, j, , st});
break;
}
}
}
while(!q.empty()) {
node now = q.front();
q.pop();
if(now.st == (<<n*m) - ) return now.dis;
if(!vis[now.st][now.x1][now.y1][now.x2][now.y2]) vis[now.st][now.x1][now.y1][now.x2][now.y2] = true;
else continue;
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
int x = now.x1 + dir[i][];
int y = now.y1 + dir[i][];
int xx = now.x2 + dir[j][];
int yy = now.y2 + dir[j][];
if( <= x && x <= n && <= y && y <= m && <= xx && xx <= n && <= yy && yy <= m && s[x][y] != 'X' && s[xx][yy] != 'X') {
q.push(node{x, y, xx, yy, now.dis+, now.st|(<<get(x, y))|(<<get(xx, yy))});
}
}
}
}
return ;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = ; i <= n; i++) {
scanf("%s", s[i]+);
}
printf("%d\n", bfs());
return ;
}

牛客小白月赛7 CSL的校园卡的更多相关文章

  1. 树的最长链-POJ 1985 树的直径(最长链)+牛客小白月赛6-桃花

    求树直径的方法在此转载一下大佬们的分析: 可以随便选择一个点开始进行bfs或者dfs,从而找到离该点最远的那个点(可以证明,离树上任意一点最远的点一定是树的某条直径的两端点之一:树的直径:树上的最长简 ...

  2. 牛客网 牛客小白月赛5 I.区间 (interval)-线段树 or 差分数组?

    牛客小白月赛5 I.区间 (interval) 休闲的时候写的,但是写的心情有点挫,都是完全版线段树,我的一个队友直接就水过去了,为啥我的就超内存呢??? 试了一晚上,找出来了,多初始化了add标记数 ...

  3. 牛客小白月赛8 - E - 诡异数字 数位DP

    牛客小白月赛8 - E - 诡异数字 题意: 求区间中,满足限制条件的数字的个数. 限制条件就是某些数字不能连续出现几次. 思路: 比较裸的数位DP, DP数组开一个dp[len][x][cnt] 表 ...

  4. 牛客小白月赛18 Forsaken给学生分组

    牛客小白月赛18 Forsaken给学生分组 Forsaken给学生分组 链接:https://ac.nowcoder.com/acm/contest/1221/C来源:牛客网 ​ Forsaken有 ...

  5. 牛客小白月赛18 Forsaken喜欢数论

    牛客小白月赛18 Forsaken喜欢数论 题目传送门直接点标题 ​ Forsaken有一个有趣的数论函数.对于任意一个数xxx,f(x)f(x)f(x)会返回xxx的最小质因子.如果这个数没有最小质 ...

  6. 牛客小白月赛19 E 「火」烈火燎原 (思维,树)

    牛客小白月赛19 E 「火」烈火燎原 (思维,树) 链接:https://ac.nowcoder.com/acm/contest/2272/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空 ...

  7. 【牛客小白月赛21】NC201604 Audio

    [牛客小白月赛21]NC201604 Audio 题目链接 题目大意: 给出三点 ,求到三点距离相等的点 的坐标. 解析 考点:计算几何基础. 初中蒟蒻表示不会什么法向量.高斯消元..qwq 方法一: ...

  8. 【牛客小白月赛21】NC201605 Bits

    [牛客小白月赛21]NC201605 Bits 题目链接 题目描述 Nancy喜欢做游戏! 汉诺塔是一个神奇的游戏,神奇在哪里呢? 给出3根柱子,最开始时n个盘子按照大小被置于最左的柱子. 如果盘子数 ...

  9. 牛客小白月赛16 小石的妹子 二分 or 线段树

    牛客小白月赛16 这个题目我AC之后看了一下别人的题解,基本上都是线段树,不过二分也可以. 这个题目很自然就肯定要对其中一个进行排序,排完序之后再处理另外一边,另一边记得离散化. 怎么处理呢,你仔细想 ...

随机推荐

  1. MD5算法详解

    MD5是什么 message-digest algorithm 5(信息-摘要算法).经常说的“MD5加密”,就是它→信息-摘要算法.在下载一下东西时,经常在一些压缩包属性里,看到md5值.而且这个下 ...

  2. 上传代码到github的步骤

    在你的电脑上装好git 大致流程是: 1.在github上创建项目 2.使用git clone https://github.com/xxxxxxx/xxxxx.git克隆到本地 3.编辑项目 4.g ...

  3. phpstorm 一个窗口打开多个项目

    参考:https://imshusheng.com/php/135.html 文件 -> 设置 -> 项目"XXX" -> Directories- > A ...

  4. 2018-2019-2 《网络对抗技术》Exp3 免杀原理与实践 20165211

    目录 2018-2019-2 <网络对抗技术>Exp3 免杀原理与实践 20165211 1. 基础问题回答 (1)杀软是如何检测出恶意代码的? (2)免杀是做什么? (3)免杀的基本方法 ...

  5. Jenkins serving Cake: our recipe for Windows

    https://novemberfive.co/blog/windows-jenkins-cake-tutorial/ Where we started, or: why Cake took the ...

  6. 如何自己烧制全文RSS(打造自己RSS源)

    烧制RSS源 到Feed43注册一个账号,虽说不注册也能用,但是为了方便修改自己烧制的RSS,最好还是注册一个账号来管理 到主页点击Create new feed 输入网址点击reload 可以看到请 ...

  7. 深度学习课程笔记(十五)Recurrent Neural Network

    深度学习课程笔记(十五)Recurrent Neural Network 2018-08-07 18:55:12 This video tutorial can be found from: Yout ...

  8. (转) Learning Deep Learning with Keras

    Learning Deep Learning with Keras Piotr Migdał - blog Projects Articles Publications Resume About Ph ...

  9. (转载)C# winform 在一个窗体中如何设置另一个窗体的TextBox的值

    方法1:修改控件的访问修饰符.(不建议使用此法) public System.Windows.Forms.TextBox textBox1; 在调用时就能直接访问 Form1 frm = new Fo ...

  10. Netty 核心组件笔记

    Netty是一款高效的NIO框架和工具,基于JAVA NIO提供的API实现. 在JAVA NIO方面Selector给Reactor模式提供了基础,Netty结合Selector和Reactor模式 ...