UVALive 6585 && Gym 100299F Draughts (暴力+回溯)

题意:给定一个 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;
}
时间: 2024-07-31 06:45:31

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

uva 639 Don&#39;t Get Rooked (暴力回溯 )

uva 639 Don't Get Rooked In chess, the rook is a piece that can move any number of squares vertically or horizontally. In this problem we will consider small chess boards (at most 44) that can also contain walls through which rooks cannot move. The g

暴力回溯法 解八皇后

国际象棋 八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例.该问题是国际西洋棋棋手马克斯·贝瑟尔于1848年提出:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或同一斜线上,问有多少种摆法. public class _8Queen { //回溯法,暴力解8皇后 private static int ways = 0; //返回解法个数 public static int f8queen() { int[][] board = new int

Summer Training #10 Div.2 E(暴力+回溯)

题目链接 题意:给9乘9的数独矩阵,挖去其中5个元素,要求补全其余元素 所犯错误:1.题目中所给的数独矩阵本身可能就是错的(没认真看题,wa惨了)   2.回溯时,遇到正确的答案就终止循环 #include<stdio.h> #include<string.h> #include<queue> using namespace std; bool flag[3][11][11]; int n,a[11][11],b[7][5],k,ans[7],f; bool valid

UVaLive 6591 &amp;&amp; Gym 100299L Bus (水题)

题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set>

UVaLive 6581 &amp;&amp; Gym 100299B What does the fox say? (模拟+STL)

题意:给定一些动物的叫声,然后再定某些动物的叫声,让你去除这些叫声后得到的叫声. 析:先存储所有的叫声,然后用map来记录其他的叫声,在输出时再判定一下就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #includ

UVaLive 6588 &amp;&amp; Gym 100299I (贪心+构造)

题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i  在pos 位置,那么如果 (pos-i)*2+i-1 <= n,那么可以操作一次换过来, 如果不行再换一种,如果他们之间元素是偶数,那么交换 i - pos,如果是奇数,交换 i - pos+1,然后再经过一次就可以换到指定位置. 代码如下: #pragma comment(linker, "/STACK:1

UVaLive 7457 Discrete Logarithm Problem (暴力)

题意:求一个x使得 a^x%p = b p为素数: 析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA... 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #incl

Gym - 100203A Ariel 暴力+位运算

题意:第i种生物有k[i]个特征,分数是score[i],现在要参加竞赛,报出一种生物a,和一些特征h[i],参加竞赛的所有生物在这些h[i]上面的特征是一样的,a生物有h[i],则所有竞赛的生物都必须有h[i],a生物没有,竞赛的生物也没有,没有提到的则不用管.问你在竞赛中a的排名 思路:特征最多只有10中,所有可以用二进制的每一位表示特征的状态,并记录下每种状态下的生物的类型.现在给你生物的状态,首先要求出能参加竞赛的生物的种类.当 (i&p == t[a]&p) 时,所有拥有i状态的

UVALive - 6185 Find the Outlier暴力填表+高斯消元+卡eps

https://cn.vjudge.net/problem/UVALive-6185 我真的是服了orz eps 1e5,1e6过不了 开1e2 1e1都能过 题意:给你一个d阶多项式f的f(0),f(1)...f(d+1),f(d+2) 有一个是错误的,问第几个是错的 题解:题目多给了两个方程(约束). 想了一下如果只给一个,是找不出来的. 给两个的话,可以这么考虑: 先取出一个方程X,再取剩下的n个高斯消元一下,将解得的系数带入最后一个方程,if成立,说明X是错的,else再取另一个(说明错