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. 关于C语言中for循环的执行顺序

    for(初始值赋值操作A:终止条件B:递增操作C) {      循环体D: } 其执行次序为:A->B->D->C->B->D->C->B--.. 直到B条 ...

  2. Xamarin.iOS模拟器调试找不到资源文件

    Xamarin.iOS模拟器调试找不到资源文件 在Visual Studio 2015中,运行Xamarin.iOS项目,出现找不到资源文件的错误.错误信息:System.IO.FileNotFoun ...

  3. Redis作为多个Windows服务运行配置方法

    1.首先下载微软官方推荐的版本redis-2.8.12 2.开始配置,首先复制两份redis.conf并且重命名为redis6379.conf  redis6380.conf 里面的配置节点相应的更改 ...

  4. Python核心模块——urllib模块

    现在Python基本入门了,现在开始要进军如何写爬虫了! 先把最基本的urllib模块弄懂吧. urllib模块中的方法 1.urllib.urlopen(url[,data[,proxies]]) ...

  5. HDU3247 Resource Archiver(AC自动机+BFS+DP)

    题目,求最短的包含所有n个DNA片段且不包含任何一个病毒片段的序列. 容易用所有DNA片段和病毒片段建一个AC自动机,构造fail时处理一下各个结点后缀是DNA或者病毒的情况,然后dp[S][u]表示 ...

  6. DataTable排序的一般方法

    一.重生法dstaset.Tables.Add(dt)dataset.Tables(0).DefaultView.Sort = "id desc" 二.直接法dv = New Da ...

  7. django 代码片段3

    #coding=utf-8 # 没有++ 和--其他的都一样 foo=1 show_output=True if show_output and foo==1: print 'pyhont and % ...

  8. ! cocos2d 预编译重复

    由于预编译文件重复,导致下面的类没有被编译,所以,在写代码的时候也没有提示还报错,说LoadingScene没有定义. #ifndef __HELLOWORLD_SCENE_H__ #define _ ...

  9. ubuntu14.04美化

    首先我美化grub启动菜单背景和开关机背景,还有自动换壁纸.其它的美化日后再写博文. Grub启动菜单背景更换: 这个很简单,比以前的ubuntu和grub版本简单多了,直接将图片文件放到/boot/ ...

  10. The constructor BASE64Encoder() is not accessible due to restriction on required

    在Eclipse中编写Java代码时,用到了BASE64Decoder,import sun.misc.BASE64Decoder;可是Eclipse提示: Access restriction : ...