A. The Fault in Our Cubes 暴力dfs
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的更多相关文章
- hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)
#1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...
- Strange Country II 暴力dfs
这题点的个数(<=50)有限, 所以可以纯暴力DFS去搜索 //#pragma comment(linker, "/STACK:16777216") //for c++ Co ...
- UVA129 暴力dfs,有许多值得学习的代码
紫书195 题目大意:给一个困难的串,困难的串的定义就是里面没有重复的串. 思路:不需要重新对之前的串进行判重,只需要对当前的加入的字符进行改变即可. 因为是判断字典序第k个的字符串,所以要多一个全局 ...
- 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)
//never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...
- 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 ...
- UVA 185(暴力DFS)
Roman Numerals The original system of writing numbers used by the early Romans was simple but cum ...
- 1172: 单词接龙(XCOJ 暴力DFS)
1172: 单词接龙 时间限制: 1 Sec 内存限制: 128 MB提交: 12 解决: 5 标签提交统计讨论版 题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词 ...
- 1506 传话 (暴力DFS或者Tarjan模板题)
题目描述 Description 一个朋友网络,如果a认识b,那么如果a第一次收到某个消息,那么会把这个消息传给b,以及所有a认识的人. 如果a认识b,b不一定认识a. 所有人从1到n编号,给出所有“ ...
- 【Gym - 101164I】Cubes(dfs,剪枝)
BUPT2017 wintertraining(15) #4 A - I.Cubes Gym - 101164I 题意 将n拆成最少个立方数相加的形式. 题解 根据n的范围,立方数最大不超过400的立 ...
随机推荐
- jws webservice code
1.服务器端建立 1.1.创建接口 [java] view plaincopy @WebService public interface IWebService { int add(int ...
- HDU 2746 Cyclic Nacklace
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- Typescript 常见写法
一.Typescript 中数组 let list: number[] = [1, 2, 3]; let list: Array<number> = [1, 2, 3];
- [RK3288][Android6.0] 调试笔记 --- 测试I2C设备正常传输方法【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/71515020 Platform: RockchipOS: Android 6.0Kernel ...
- Android Studio四大组件之Service
Service在Android运行在后台,它没有可视化界面,只是默默运行在后台.我们以一个后台定时器的例子清晰的说明Service的运行流程. 一.创建Service类 项目右键->New-&g ...
- 【Codeforces 762A】 k-th divisor
[题目链接] 点击打开链接 [算法] 我们知道,一个数的因子是成对出现的,一半小于等于sqrt(N),一半大于sqrt(N),因此,我们可以从 2..sqrt(N)枚举因子 [代码] #include ...
- python 使用multiprocessing需要注意的问题
我们在编写程序的时候经常喜欢这样写代码 import MySQLdb import time from multiprocessing import Process conn = MySQLdb.co ...
- LINUX-进程的概念
计算机中,CPU是最宝贵的资源,为了提高CPU的利用率,引入了多道程序设计的概念.当内存中多个程序存在时,如果不对人们熟悉的“程序”的概念加以扩充,就无法刻画多个程序共同运行时系统呈现出的特征. 一. ...
- #ifndef <标识> #define <标识> #endif
头件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都include了同一个头文件.而编译时,这两个C文件要一同编译成一个可运行文件,于是问题来了,大量的声明冲突. 还是把 ...
- chromium浏览器开发系列第一篇:如何获取最新chromium源码
背景: 最近摊上一个事儿,领导非要让写一篇技术文章,思来想去,自己接触chrome浏览器时间也不短了,干脆就总结一下吧.于是乎,本文顺理成章.由于有些细节必需描述清楚,所以这次先讲如何拿到c ...