zju 1002
// zju 1002
// #include "stdafx.h"
#include <string>
#include <iostream> using namespace std;
int N = 4;
int Max = 0;
char a[5][5];
int judge(int row, int col)//测试该坐标是否可以放置 返回 0 可放置,返回 1 不可放置
{
for (int i = row - 1; i >= 0; i--)//测试该行之前的位置
{
if (a[i][col] == '@')return 1;//不行
if (a[i][col] == 'X')break; }
for (int i = col - 1; i >= 0; i--)
{
if (a[row][i] == '@')return 1;
if (a[row][i] == 'X')break;
}
return 0;
}
void DFS(int pos, int count)
{
int row, col;
if (pos == N*N)
{
if (Max < count)
{
Max = count; return;
}
}
else
{//计算出行列坐标
row = pos / N;
col = pos % N;
//测试该位置是否可行
if (!judge(row, col)&&a[row][col]=='.')
{
a[row][col] = '@';
DFS(pos + 1, count+1);
a[row][col] = '.';//恢复数据
}
DFS(pos + 1, count);//该位置不放置
}
} int main()
{ while (scanf_s("%d",&N)!=EOF&&N)
{
memset(a, 0, sizeof(a));//快速清零
for (int i = 0; i < N; i++)
{ for (int j = 0; j < N; j++)
{
//scanf_s("%c", a[i][j]);
cin >> a[i][j];
}
}
DFS(0, 0);
cout << Max << endl;
Max = 0;
}
return 0;
}
老师还说了一种改良算法,以后有空再写。。。又是只加了几句而已。。。
AC 记得#include <stdio.h>
zju 1002的更多相关文章
- [ZJU 1002] Fire Net
ZOJ Problem Set - 1002 Fire Net Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose that we ha ...
- ZOJ(ZJU) 1002 Fire Net(深搜)
Suppose that we have a square city with straight streets. A map of a city is a square board with n r ...
- [ZOJ 1002] Fire Net (简单地图搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002 题目大意: 给你一个n*n的地图,地图上的空白部分可以放棋 ...
- ZOJ Problem Set - 1002(DFS)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1002 题意:给出一个n,有n*n大小的城市,(.)表示空地,从碉堡(O)射 ...
- 1002. 写这个号码 (20)(数学啊 ZJU_PAT)
主题链接:http://pat.zju.edu.cn/contests/pat-b-practise/1002 读入一个自然数n,计算其各位数字之和.用汉语拼音写出和的每一位数字. 输入格式:每一个測 ...
- [acm 1002] 浙大 Fire Net
已转战浙大 题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=2 浙大acm 1002 #include <iostre ...
- Bestcoder#5 1002
Bestcoder#5 1002 Poor MitsuiTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- acm 1002 算法设计
最近突然想往算法方向走走,做了做航电acm的几道题 二话不说,开始 航电acm 1002 题主要是处理长数据的问题,算法原理比较简单,就是用字符数组代替int,因为int太短需要处理的数据较长 下面是 ...
- BestCoder Round 69 Div 2 1001&& 1002 || HDU 5610 && 5611
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5610 如果杠铃总质量是奇数直接impossible 接着就考验耐心和仔细周全的考虑了.在WA了三次后终于发 ...
随机推荐
- html5新增语义标签
1.header <header> 标签定义文档的页眉(介绍信息). 2.nav <nav> 标签定义导航链接的部分. 3.article <article> 标签 ...
- 戴尔商务机OptiPlex5040问题
windows安装程序无法将Windows配置为在此计算机的硬件 你讲的那个提示准确讲应该是在系统装完重启后进入硬件检测和对应驱动开始阶段,应该是突然提示出来:windows安装程序无法将window ...
- django book querysets
from __future__ import unicode_literals from django.db import models from django.contrib.auth.models ...
- 帝国CMS列表模板页面内容截取
$listtemp = '<div class="c_n_item">';$listtemp .= '<div class="c_n_title&quo ...
- @Override的作用
@Override是伪代码,表示重写(不写也可以,但是有些IDE会报warning),不过写上有如下好处: 1.可以当注释用,方便阅读:2.编译器可以给你验证@Override下面的方法名是否是你父类 ...
- 分享大家一个背景为下雪的JQuery
<html><head> <meta charset="utf-8"> <meta content="IE=edge,chrom ...
- 11.写一个函数,尽可能高效的,从一个标准 url 里取出文件的扩展名
//首先列出需要被操作的url $url_path = "http://www.sina.com.cn/abc/de/fg.php?id=1"; 方法一: ...
- gulp详细入门教程(转载)
本文转载自: gulp详细入门教程
- webApp 开发技术要点总结
如果你是一名前端er,又想在移动设备上开发出自己的应用,那怎么实现呢?幸好,webkit内核的浏览器能帮助我们完成这一切.接触 webkit webapp的开发已经有一段时间了,现把一些技巧分享给大家 ...
- 【转】PowerShell入门(三):如何快速地掌握PowerShell?
转至:http://www.cnblogs.com/ceachy/archive/2013/02/01/HowToLearnPowerShell.html 如何快速地掌握PowerShell呢?总的来 ...