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了三次后终于发 ...
随机推荐
- windows7打印时,显示脱机,提示“服务器打印后台处理程序服务没有运行”。
1. 问题 windows7打印时,显示脱机,提示“服务器打印后台处理程序服务没有运行”. 2. 解决方法. 将下面的文字保存为bat文件执行,其中\\192.168.40.110\Lenovo M7 ...
- Nginx基础整理
目录结构如下: Nginx基础知识 Nginx HTTP服务器的特色及优点 Nginx的主要企业功能 Nginx作为web服务器的主要应用场景包括: Nginx的安装 安装环境 快速安装命令集合 各个 ...
- [Android Tips] 14. Using Proguard with Android without obfuscation
Option -dontobfuscate REF Using Proguard with Android without obfuscation
- 20145320《Java程序设计》第二次实验报告
20145320<Java程序设计>第二次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.04.12 15: ...
- ubuntu 下安装 wxpython2.8
echo "deb http://archive.ubuntu.com/ubuntu wily main universe" | sudo tee /etc/apt/sources ...
- JS获取当前时间并把时间赋给input表单
<script>window.onload = function(){ function getDate(){ debugger; var today = new Date(); var ...
- mysql中and和or
and的优先级高于or,所以一个sql语句中如果and和or同时出现,则or要加括号
- MVC4 Filter 验证客户端访问类型(移动端、PC端)
Filter: 1 /// <summary> /// 检测是否是手机访问 /// </summary> public class IsMobileFilter : Actio ...
- 如何做个简单安卓App流程
有同学做毕业设计,问怎样做个简单安卓App流程,我是做服务端的,也算是经常接触app,想着做app应该很简单吧,不就做个页面,会跳转,有数据不就行了,我解释了半天,人家始终没听懂,算了,我第二天问了下 ...
- SharePoint 2013 一些小技巧
一.添加“SharePoint 2013 切换用户”标签 相比SharePoint 2010,SharePoint2013版本去掉了切换用户登陆的功能(如下图),其实这个可以通过改welcome.as ...