http://codeforces.com/gym/101257/problem/A

把它固定在(0,0, 0)到(2, 2, 2)上,每次都暴力dfs检查,不会超时的,因为规定在这个空间上,一不行,就会早早退出。

这样写起来比较好写。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = + ;
bool vis[][][];
char str[maxn];
int fx[] = {, , , -, , };
int fy[] = {, , -, , , };
int fz[] = {, , , , -, };
bool check(int x, int y, int z) {
if (x < || y < || z < ) return false;
if (x > || y > || z > ) return false;
if (vis[x][y][z]) return false;
return true;
}
int op[];
bool dfs(int cur, int x, int y, int z, int dir) {
int tx = fx[dir] + x, ty = fy[dir] + y, tz = fz[dir] + z;
if (cur == ) {
if (check(tx, ty, tz)) return true;
else return false;
}
if (!check(tx, ty, tz)) return false;
if (str[cur] == 'I') {
vis[tx][ty][tz] = true;
if (dfs(cur + , tx, ty, tz, dir)) {
return true;
} else {
vis[tx][ty][tz] = false;
return false;
}
} else {
vis[tx][ty][tz] = true;
for (int i = ; i < ; ++i) {
if (dir == i || op[dir] == i) continue;
if (dfs(cur + , tx, ty, tz, i)) {
return true;
}
}
vis[tx][ty][tz] = false;
return false;
}
}
void work() {
op[] = ;
op[] = ;
op[] = ;
op[] = ;
op[] = ;
op[] = ;
scanf("%s", str + );
for (int i = ; i <= ; ++i) {
if (str[i] == 'E') {
cout << "NO" << endl;
return;
}
}
for (int i = ; i < ; ++i) {
for (int j = ; j < ; ++j) {
for (int k = ; k < ; ++k) {
vis[i][j][k] = true;
if (dfs(, i, j, k, )) {
cout << "YES" << endl;
return;
}
vis[i][j][k] = false;
}
}
}
cout << "NO" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

A. The Fault in Our Cubes 暴力dfs的更多相关文章

  1. hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)

    #1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...

  2. Strange Country II 暴力dfs

    这题点的个数(<=50)有限, 所以可以纯暴力DFS去搜索 //#pragma comment(linker, "/STACK:16777216") //for c++ Co ...

  3. UVA129 暴力dfs,有许多值得学习的代码

    紫书195 题目大意:给一个困难的串,困难的串的定义就是里面没有重复的串. 思路:不需要重新对之前的串进行判重,只需要对当前的加入的字符进行改变即可. 因为是判断字典序第k个的字符串,所以要多一个全局 ...

  4. 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)

    //never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...

  5. Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)

    题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...

  6. UVA 185(暴力DFS)

      Roman Numerals  The original system of writing numbers used by the early Romans was simple but cum ...

  7. 1172: 单词接龙(XCOJ 暴力DFS)

    1172: 单词接龙 时间限制: 1 Sec  内存限制: 128 MB提交: 12  解决: 5 标签提交统计讨论版 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词 ...

  8. 1506 传话 (暴力DFS或者Tarjan模板题)

    题目描述 Description 一个朋友网络,如果a认识b,那么如果a第一次收到某个消息,那么会把这个消息传给b,以及所有a认识的人. 如果a认识b,b不一定认识a. 所有人从1到n编号,给出所有“ ...

  9. 【Gym - 101164I】Cubes(dfs,剪枝)

    BUPT2017 wintertraining(15) #4 A - I.Cubes Gym - 101164I 题意 将n拆成最少个立方数相加的形式. 题解 根据n的范围,立方数最大不超过400的立 ...

随机推荐

  1. Continuous integration: The answer to life, the universe, and everything?

    Continuous integration is not always the right answer. Here's why. https://techbeacon.com/continuous ...

  2. socketIO原理图

  3. VC实现趋势图绘制

    本文参考pudn上一个完整工程,在pudn搜索“50815867CurveDrawing”即可找到源代码.   上图是使用VS2010重写了该软件后的效果图,下面再贴出关键代码: // Plot.cp ...

  4. 有关 安装MySQL的错误

    1.登录SQLyog 密码与MySQL设置不一致. 2.上一次安装MySQL没有卸载干净,(排查删除: (1)搜索C盘删除相关文件(隐藏目录   C:\ProgramData  下寻找 mysql ) ...

  5. 蓝牙BlueTooth技术学习理解

    1.BLUETOOTH基本了解 BLUETOOTH出自丹麦 Bluetooth SIG 蓝牙技术联盟,非盈利组织.主要任务是发布蓝牙规格.管理资格认证程序.保护蓝牙商标及宣传蓝牙无线技术. 重要网站 ...

  6. js中的逻辑与(&&)与逻辑或(||)

    var foo = 1; var bar = 0; var tar = false; var baz = 2; 一.js中的逻辑与(&&) 1.当第一个数为true时,返回第二个数: ...

  7. read appSettings in configuration file by XElement with xmlns

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-write-queries- ...

  8. Oracle:通过dbv查看数据文件是否有坏块

    我们备份的数据文件,可以通过oacle自带的dbv工具来查看是否是好的. 下面实验如下: 环境:oracle10.2.0.1 1.检查数据文件是否有坏块 [oracle@app orcl]$ dbv ...

  9. jstl标签: c:Foreach详解

    为循环控制,它可以将集合(Collection)中的成员循序浏览一遍.运作方式为当条件符合时,就会持续重复执行的本体内容. 为循环控制,它可以将集合(Collection)中的成员循序浏览一遍.运作方 ...

  10. 推箱子 Sokoban(华中农业比赛)

    点这里 打开题目链接   点击打开链接 题目就是我们玩过的推箱子: 一顿暴力广搜:加状态标记.状态压缩需要用到一个类似于康拓的思想来压缩:所以容易TLE,搜索就是用一个int型的数字来表示一个状态, ...