zoj 1019

// C++Exercise.cpp : 定义控制台应用程序的入口点。
//

#include<iostream>
#include<string>
#include<cstring>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<sstream>
using namespace std;

int t, m, n;

typedef struct{
	int steps_min;
	int steps_max;
	char dir;
}choose;

vector<choose> operate;

bool feasible(vector<vector<int> >& area, int x, int y, int index){
	if (index == operate.size()) return true;
	int start = operate[index].steps_min;
	int end = operate[index].steps_max;
	int k;
	if (operate[index].dir == 'R'){
		for (int i = start; i <= end; i++){
			if (y + i < n&&area[x][y + i] != 1){
				for (k = y + i; k > y; k--){
					if (area[x][k]) break;
				}
				if (k==y&&feasible(area, x, y + i, index + 1)) return true;
			}
			else break;
		}
	}
	else if (operate[index].dir == 'L'){
		for (int i = start; i <= end; i++){
			if (y - i >= 0&&area[x][y - i] != 1 ){
				for (k = y - i; k < y; k++){
					if (area[x][k]) break;
				}
				if (k==y&&feasible(area, x, y - i, index + 1)) return true;
			}
			else break;
		}
	}
	else if (operate[index].dir == 'U'){
		for (int i = start; i <= end; i++){
			if (x - i >= 0&&area[x - i][y] != 1 ){
				for (k = x - i; k < x; k++){
					if (area[k][y]) break;
				}
				if (k==x&&feasible(area, x - i, y, index + 1)) return true;
			}
			else break;
		}
	}
	else if (operate[index].dir == 'D'){//'D'
		for (int i = start; i <= end; i++){
			if (x + i < m&&area[x + i][y] != 1){
				for (k = x + i; k > x; k--){
					if (area[k][y]) break;
				}
				if (k==x&&feasible(area, x + i, y, index + 1)) return true;
			}
			else break;
		}
	}
	return false;
}


int main(){
	cin >> t;
	while (t--){
		cin >> m >> n;
		vector<vector<int> > area(m, vector<int>(n, 0));
		for (int i = 0; i < m; i++){
			for (int j = 0; j < n; j++){
				cin >> area[i][j];
			}
		}
		operate.clear();
		int i, j;
		while (cin >> i >> j){
			if (i == 0 && j == 0) break;
			if (i > j) swap(i, j);
			char dir;
			cin >> dir;
			choose temp;
			temp.steps_min = i;
			temp.steps_max = j;
			temp.dir = dir;
			operate.push_back(temp);
		}
		int count = 0;
		for (i = 0; i < m; i++){
			for (j = 0; j < n; j++){
				if (area[i][j] == 1) continue;
				if (feasible(area, i, j, 0)){
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值