题意:给定一个 10*10的矩阵,每一个W可以跳过一个B向对角走到#并把B吃掉,并且可以一直跳直到不能动为止,现在是W走的时候,问你最多吃几个B。

析:直接暴力+回溯,深搜就好。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 26 + 5;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
char s[15][15];
int ans; void dfs(int r, int c, int cnt){
ans = Max(ans, cnt);
for(int i = 4; i < 8; ++i){
int x = r + dr[i];
int y = c + dc[i];
int xx = x + dr[i];
int yy = y + dc[i]; if(is_in(xx, yy) && s[x][y] == 'B' && s[xx][yy] == '#'){
s[x][y] = '#';
dfs(xx, yy, cnt+1);
s[x][y] = 'B';
}
}
} int main(){
int T; cin >> T;
n = m = 10;
while(T--){
for(int i = 0; i < 10; ++i) scanf("%s", s+i); ans = 0;
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
if(s[i][j] == 'W'){ s[i][j] = '#'; dfs(i, j, 0); s[i][j] = 'W'; } printf("%d\n", ans);
}
return 0;
}

UVaLive 6585 && Gym 100299F Draughts (暴力+回溯)的更多相关文章

  1. FZU 2107 Hua Rong Dao(暴力回溯)

    dfs暴力回溯,这个代码是我修改以后的,里面的go相当简洁,以前的暴力手打太麻烦,我也来点技术含量.. #include<iostream> #include<cstring> ...

  2. uva 639 Don't Get Rooked 变形N皇后问题 暴力回溯

    题目:跟N皇后问题一样,不考虑对角冲突,但考虑墙的存在,只要中间有墙就不会冲突. N皇后一行只能放一个,而这题不行,所以用全图暴力放棋,回溯dfs即可,题目最多就到4*4,范围很小. 刚开始考虑放一个 ...

  3. Codeforces Gym 100531D Digits 暴力

    Problem D. Digits 题目连接: http://codeforces.com/gym/100531/attachments Description Little Petya likes ...

  4. UVALive 7070 The E-pang Palace 暴力

    The E-pang Palace Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem ...

  5. Codeforces Gym 100418K Cards 暴力打表

    CardsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action? ...

  6. UVALive - 4026 Difficult Melody(暴力)

    我这个英语学渣又把题给翻译错了……(话说,六级差十分没有过,好心疼T T),题目中说的P和Q都是计算game的个数,我以为是出现的次数,各种wa..后来调整了以后又是各种wa,原来是double型的数 ...

  7. Chinese Mahjong UVA - 11210 (暴力+回溯递归)

    思路:得到输入得到mj[]的各个牌的数量,还差最后一张牌.直接暴力枚举34张牌就可以了. 当假设得到最后一张牌,则得到了的牌看看是不是可以胡,如果可以胡的话,就假设正确.否者假设下一张牌. 关键还是如 ...

  8. Gym 100531D Digits (暴力)

    题意:给定一个数字,问你找 n 个数,使得这 n 个数各位数字之和都相等,并且和最小. 析:暴力,去枚举和是 1 2 3...,然后去选择最小的. 代码如下: #pragma comment(link ...

  9. UVALive 7279 Sheldon Numbers (暴力打表)

    Sheldon Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/H Description According t ...

随机推荐

  1. 操作系统学习(三)-- CPU调度

    操作系统之进程与线程 L14 CPU调度策略 如何设计调度算法? 调度关键在:折中和综合 IO约束型的任务一般是前台任务,和用户交互:CPU约束型关注周转时间 进程切换过程需要系统内耗,切换时间长则系 ...

  2. C#中Queue&lt;T&gt;类的使用以及部分方法的源代码分析

    Queue<T>类 表示对象的先进先出集合. 队列在按接收顺序存储消息方面很实用,以便于进行顺序处理. 存储在 Queue,<T> 中的对象在一端插入,从还有一端移除. Que ...

  3. 《Getting Started with WebRTC》第二章 WebRTC技术介绍

    <Getting Started with WebRTC>第二章 WebRTC技术介绍 本章作WebRTC的技术介绍,主要讲下面的概念:   .  怎样建立P2P的通信   .  有效的信 ...

  4. 常见iOS面试题 之 怎么判断一个类是否遵循某个协议

    答案: 使用方法conformsToProtocol. 调用例子: BOOL isConform = [Student conformsToProtocol:@protocol(UIScrollVie ...

  5. NOI 2014简要题解

    Day 1.Problem A. 起床困难综合症 100分做法: 把数字看成二进制数.对于初始攻击力.我们将其拆成32位,并求出每一位为0和1时经过全部防御门之后分别得到的数字.然后就是按位贪心了,我 ...

  6. PyOpenGL下GlutBitmapCharacter的替代

    虽然pyinstaller支持pyopengl,但是调用GLUT之后,在其它电脑上面运行就会出现错误,索性按照之前C#上面的办法,把字体数据和函数用python重写 fontData.py #! /u ...

  7. Visual Studio自动生成文件版本信息

    一.     前言 通常,要控制输出文件的版本信息,只需要手动修改资源rc文件中的Version,即可在输出文件的文件属性里查看到对应的版本信息.如下图:    但是,版本号是会随时都更新的,每次bu ...

  8. python day - 09 函数

    函数 1.函数的定义,引用. 定义:函数是对功能和代码块的封装和定义. 函数用 def关键字来表示. 格式: def  函数名(): 函数体 eg: return(返回值) 在函数中遇到return ...

  9. app上架的问题

    1..p12证书文件(钥匙串导出)开发证书和描述文件的 2.app打包好重Xcode上传到iTunes中的时候最好做校验: 3.程序跑真机出现的问题 解决方法:debug 模式改成release模式 ...

  10. Spring Base

    1.在java开发领域,Spring相对于EJB来说是一种轻量级的,非侵入性的Java开发框架,曾经有两本很畅销的书<Expert one-on-one J2EE Design and Deve ...