1.POJ2488  A Knight's Journey

search

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std; #define N 27
#define INF 0x7FFFFFFF
int p,q,_count=;
int _dec[N][N];
int routine[*N];
int t1,t2;
int flag,flag2; void path(int x,int y,int k)
{
switch (k)
{
case :{t1 = x-;t2 = y-;break;}
case :{t1 = x+;t2 = y-;break;}
case :{t1 = x-;t2 = y-;break;}
case :{t1 = x+;t2 = y-;break;}
case :{t1 = x-;t2 = y+;break;}
case :{t1 = x+;t2 = y+;break;}
case :{t1 = x-;t2 = y+;break;}
case :{t1 = x+;t2 = y+;break;}
}
}
void OUTPUT()
{
for (int i=;i<_count;i++)
{
cout<<(char)('A'+routine[*i+])<<routine[*i]+;
if (i==_count-) cout<<endl;
}
}
bool DFS(int x,int y)
{
if (flag2 == ) return ;
_dec[x][y]=;
routine[*_count]=x;
routine[*_count+]=y;
_count++;
if (_count>p*q)
{
flag2 = ;
return ;
}
if ((_count == p*q)&&(flag == ))
{
OUTPUT();
flag = ;
return ;
}
for (int k=;k<;k++)
{
path(x,y,k);
int xx=t1,yy = t2;
if ((xx>=)&&(xx<p)&&(yy>=)&&(yy<q)&&(_dec[xx][yy]==))
if (DFS(xx,yy)) return ;
}
_dec[x][y]=;
_count--;
return ;
}
int main()
{
int n;
cin>>n;
for (int m=;m<=n;m++)
{
for (int i=;i<N;i++)
for (int j=;j<N;j++)
_dec[i][j]=;
memset(routine,,sizeof(routine));
cin>>p>>q;
cout<<"Scenario #"<<m<<":"<<endl;
if ((p==)&&(q==))
{
cout<<"A1"<<endl<<endl;
continue;
}
if (p*q> || p>= || q>= || p<= || q<=)
{
cout<<"impossible"<<endl<<endl;
continue;
}
_count = ;
flag = ;
flag2 = ;
DFS(,);
if ((flag2 == )||(flag==)) cout<<"impossible"<<endl;
cout<<endl;
}
return ;
}

2.POJ 1077 Eight

http://blog.csdn.net/whyorwhnt/article/details/10555989

Union Find and search的更多相关文章

  1. Vue + GraphQL初试

    基本用法 GraphQL概述 GraphQL基本语法特性 GraphQL类型系统 GraphQL类型系统内置基础类型 GraphQL类型系统内置修饰符 GraphQL工作原理 GraphQL执行过程 ...

  2. Search Quick Union Find(图的存储结构)

    Quick Find:适用于search频繁的情况 每个节点有一个id值,id相同表示两个节点相连通.在union时要将等于某一个id值都改成另一个id值 Quick Union: 适用于union频 ...

  3. ecshop /search.php SQL Injection Vul

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 ECSHOP商城系统Search.php页面过滤不严导致SQL注入漏洞 ...

  4. dedecms /plus/search.php SQL Injection && Local Variable Overriding

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 这个文件有两处注入漏洞 . $typeid变量覆盖导致ChannelTy ...

  5. 集成 Union Pay - 银联支付

    作者感言 前面已经把WeChat SDK的支付, AliPay SDK搞得七七八八了, 接下来就是银联支付的Union Pay SDK.最后:如果你有更好的建议或者对这篇文章有不满的地方, 请联系我, ...

  6. 论文阅读笔记四十七:Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression(CVPR2019)

    论文原址:https://arxiv.org/pdf/1902.09630.pdf github:https://github.com/generalized-iou 摘要 在目标检测的评测体系中,I ...

  7. [IR] XPath for Search Query

    XPath 1.0 XPath Containment Distributed Query Evaluation RE and DFA XPath 1.0 -- 在XML中的使用 XPath 语法: ...

  8. bWAPP练习--injection篇SQL Injection (GET/Search)

    SQL注入: SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意)的SQL命令注入到 ...

  9. Union比or快 Using UNION is faster when it comes to cases like scan two different column。

    problem: 595. Big Countries A country is big if it has an area of bigger than 3 million square km or ...

随机推荐

  1. php中count获取多维数组长度的方法

    转自:http://www.jb51.net/article/57021.htm 本文实例讲述了php中count获取多维数组长度的实现方法.分享给大家供大家参考.具体分析如下: 先来看看下面程序运行 ...

  2. WPF的Presenter(ContentPresenter)(转)

    这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...

  3. 移动开单软件 手持PDA开单扫描打印系统开发介绍

    具体功能预览--(图示) PDA开单打印扫描采集器主程序: ▲门店使用:接单员销售开单.销售退货或查询相关资料. ▲仓库使用:PDA仓库验收货.发货.仓库盘点 ▲在外业务开单:业务在外面开销售单.销售 ...

  4. Train Problem I (HDU 100题纪念)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. http://blog.csdn.net/shangboerds/article/details/44175667

    http://blog.csdn.net/shangboerds/article/details/44175667

  6. 使用“Empty 模式”改进 Null Object

    概述 Null Object 是Martin 大师提出的一种重构手段,其思想就是通过多态(派生一个Null对象)来减少逻辑(if … then …else)的判断. 而.NET中已经有Null Obj ...

  7. 阿牛的EOF牛肉串[HDU2047]

    阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  8. BZOJ3831 : [Poi2014]Little Bird

    设f[i]表示到i最少休息次数,f[i]=min(f[j]+(h[j]<=a[i])),i-k<=j<i,单调队列优化DP #include<cstdio> #defin ...

  9. intro.js 页面引导简单用法

    下载地址:http://pan.baidu.com/share/link?shareid=1894002026&uk=1829018343 <!DOCTYPE HTML PUBLIC & ...

  10. MySQL添加字段和修改字段的方法

    添加表字段 alter table table1 add transactor varchar(10) not Null; alter table   table1 add id int unsign ...