/*
爆搜,正解弃坑
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
const int maxn = ;
int n,m,x1[maxn],y1[maxn],x2[maxn],y2[maxn],vis[maxn][maxn],p[maxn][maxn],l[maxn];
bool dfs(int col,int stp,int y,int x){
if(y == y2[col] && x == x2[col]){
l[col] = stp;
if(col == m){
int tmpl = ;
for(int i = ;i <= m;i++) tmpl += l[i];
if(tmpl == n*n) return true;
else return false;
}
return dfs(col+,,y1[col+],x1[col+]);
}
vis[y][x] = col;
int ty,tx;
for(int i = ;i <= ;i+=){
if(i == ){
ty = y - ;
tx = x;
}else if(i == ){
ty = y;
tx = x - ;
}else if(i == ){
ty = y;
tx = x + ;
}else{
ty = y + ;
tx = x;
}
if(ty < || ty > n || tx < || tx > n || (vis[ty][tx] && (ty != y2[col] || tx != x2[col]))) continue;
p[y][x] = i;
if(dfs(col,stp+,ty,tx)) return true;
}
if(y != y1[col] || x != x1[col])vis[y][x] = ;
return false;
}
int main(){
freopen("jian.in","r",stdin);
freopen("jian.out","w",stdout);
cin>>n>>m;
for(int i = ;i <= m;i++){
cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
vis[y1[i]][x1[i]] = vis[y2[i]][x2[i]] = i;
}
dfs(,,y1[],x1[]);
int nowy,nowx;
for(int i = ;i <= m;i++){
cout<<l[i]<<endl;
nowy = y1[i];
nowx = x1[i];
for(int j = ;j <= l[i];j++){
cout<<nowx<<" "<<nowy<<endl;
if(p[nowy][nowx] == ) nowy--;
else if(p[nowy][nowx] == ) nowx--;
else if(p[nowy][nowx] == ) nowx++;
else if(p[nowy][nowx] == ) nowy++;
}
}
return ;
}

清北暑假模拟day2 将的更多相关文章

  1. 清北暑假模拟day2 之

    /* 现场代码,枚举每条边删除 */ #include<iostream> #include<cstdio> #include<string> #include&l ...

  2. 清北暑假模拟day2 国

    [题目描述]在世界的东边,有三瓶雪碧.--laekov黎大爷为了虐 zhx,给 zhx 出了这样一道题.黎大爷搞了一个数据结构,但是他没有告诉 zhx 这到底是什么数据结构,我们只知道这是一个数据结构 ...

  3. 清北暑假模拟day1 艳阳天

    /* 注意P有可能不是质数,不要用欧拉函数那一套,正解可以倍增,就是等比数列和的性质,注意n是否为奇数 */ #include <cstdio> #include <algorith ...

  4. 清北暑假模拟day1 生活

    /* 数字三角形,要求第K大的值,可以推知,如果得知k的范围,那么一定是在上一行可转移状态的对应范围内(反证法可以证明),这个在背包九讲里也有提及 */ #include<cstdio> ...

  5. 清北暑假模拟day1 爱

    /* 水题 */ #include<iostream> #include<cstdio> #include<string> #include<cstring& ...

  6. 清北学堂模拟赛day7 数字碰撞

    /* clj:水题别人都满分你不是你就完了,所以说水题一定要细心一点,有这么几个细节:①前导零的处理,全是零的时候要特判②换行要注意,不要多大一行,剩下就是水水的模拟了 */ #include< ...

  7. 清北学堂模拟赛d4t1 a

    分析:大模拟,没什么好说的.我在考场上犯了一个超级低级的错误:while (scanf("%s",s + 1)),导致了死循环,血的教训啊,以后要记住了. /* 1.没有发生改变, ...

  8. 清北学堂模拟赛day7 错排问题

    /* 考虑一下已经放回m本书的情况,已经有书的格子不要管他,考虑没有书的格子,不考虑错排有(n-m)!种,在逐步考虑有放回原来位置的情况,已经放出去和已经被占好的格子,不用考虑,剩下全都考虑,设t=x ...

  9. 清北学堂模拟赛day7 石子合并加强版

    /* 注意到合并三堆需要枚举两个端点,其实可以开一个数组记录合并两堆的结果,标程好像用了一个神奇的优化 */ #include<iostream> #include<cstdio&g ...

随机推荐

  1. Sender

    多个对象用同一个方法的时候,想对多个对象分别操作的话就用Sender.  BackGroundWorker worker1 = sender as BackGroundWork.  分别去取当前的对象 ...

  2. linux下安装zookeeper(单机版)

    Zookeeper 分布式服务框架是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务.状态同步服务.集群管理.分布式应用配置项的管理等.本文主要从使用者角度来介绍一下Zookeeper ...

  3. Altium Designer 15 --- PCB 3D View

    press 3 key to swith to 3D view, and press shift key and dont' loose your grip, hold the right mouse ...

  4. Mysql数据库基本操作 (一)

    1.使用mysql数据库的必备要素 a. 安装MySQL服务端 b. 安装MySQL客户端 c. [客户端]连接[服务端] d. [客户端]发送命令给[服务端MySQL]服务的接受命令并执行相应操作( ...

  5. Tomcat 的 ErrorPage 实现原理分析

    使用Tomcat,一定见到过404,500的时候,见到过Tomcat提供的错误页面,例如请求的资源找不到的时候,响应状态码为404,这个时候的错误页面是这样的: 这些错误页面是 如何生成及定位展示的  ...

  6. swfUpload 上传图片

    前端: <script src="~/Scripts/swfupload/swfupload.js"></script> <script src=&q ...

  7. linux 相关快捷键

    linux 相关快捷键 http://linux.chinaunix.net/begin/2004-10-05/34.shtml#_Toc41417098 1.使用虚拟控制台登录后按“Alt+F2”键 ...

  8. Object.ReferenceEquals

    https://msdn.microsoft.com/en-us/library/system.object.referenceequals(v=vs.110).aspx However, the r ...

  9. marshal intptr to delegate

    http://www.codeproject.com/Tips/441743/A-look-at-marshalling-delegates-in-NET https://msdn.microsoft ...

  10. C# unmanaged function pointers for iOS

    C# unmanaged function pointers for iOS Just a reminder to myself when I need this thing next time fo ...