清北暑假模拟day2 将


/*
爆搜,正解弃坑
*/
#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 将的更多相关文章
- 清北暑假模拟day2 之
/* 现场代码,枚举每条边删除 */ #include<iostream> #include<cstdio> #include<string> #include&l ...
- 清北暑假模拟day2 国
[题目描述]在世界的东边,有三瓶雪碧.--laekov黎大爷为了虐 zhx,给 zhx 出了这样一道题.黎大爷搞了一个数据结构,但是他没有告诉 zhx 这到底是什么数据结构,我们只知道这是一个数据结构 ...
- 清北暑假模拟day1 艳阳天
/* 注意P有可能不是质数,不要用欧拉函数那一套,正解可以倍增,就是等比数列和的性质,注意n是否为奇数 */ #include <cstdio> #include <algorith ...
- 清北暑假模拟day1 生活
/* 数字三角形,要求第K大的值,可以推知,如果得知k的范围,那么一定是在上一行可转移状态的对应范围内(反证法可以证明),这个在背包九讲里也有提及 */ #include<cstdio> ...
- 清北暑假模拟day1 爱
/* 水题 */ #include<iostream> #include<cstdio> #include<string> #include<cstring& ...
- 清北学堂模拟赛day7 数字碰撞
/* clj:水题别人都满分你不是你就完了,所以说水题一定要细心一点,有这么几个细节:①前导零的处理,全是零的时候要特判②换行要注意,不要多大一行,剩下就是水水的模拟了 */ #include< ...
- 清北学堂模拟赛d4t1 a
分析:大模拟,没什么好说的.我在考场上犯了一个超级低级的错误:while (scanf("%s",s + 1)),导致了死循环,血的教训啊,以后要记住了. /* 1.没有发生改变, ...
- 清北学堂模拟赛day7 错排问题
/* 考虑一下已经放回m本书的情况,已经有书的格子不要管他,考虑没有书的格子,不考虑错排有(n-m)!种,在逐步考虑有放回原来位置的情况,已经放出去和已经被占好的格子,不用考虑,剩下全都考虑,设t=x ...
- 清北学堂模拟赛day7 石子合并加强版
/* 注意到合并三堆需要枚举两个端点,其实可以开一个数组记录合并两堆的结果,标程好像用了一个神奇的优化 */ #include<iostream> #include<cstdio&g ...
随机推荐
- win7下firefox浏览器不能使用
win7下firefox浏览器不能使用,只有360浏览器才能使用. 使用360安全卫士,到更多工具里面选择"LSP修复",就可以了. 原来是因为安装了土豆加速,然后卸载导致的. 看 ...
- HDU 5907 Find Q(简单字符串)
传送门 Description Byteasar is addicted to the English letter 'q'. Now he comes across a string S consi ...
- CF 702B Powers of Two(暴力)
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:3 second memory limit per test: ...
- HDU 1874 畅通工程续(最短路/spfa Dijkstra 邻接矩阵+邻接表)
题目链接: 传送门 畅通工程续 Time Limit: 1000MS Memory Limit: 65536K Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路. ...
- Git工具:Widows下的使用(提交到Github)
2016年12月9日17:07:07 Git工作原理 http://deweixu.me/2016/11/05/how-git-works/ 2016年12月1日14:25:23 ---------- ...
- BZOJ1812 [IOI2005]river
传送门: 很常规的一道树规,转为左儿子右兄弟. 然后$f[node][anc][K]$表示在node节点上,最近的有贡献祖先在anc上,在node的儿子和兄弟上有k个有贡献节点的最优值. 然后得出以下 ...
- ::before/:before和::after/:after的使用
::before/:before和::after/:after的使用 之前总是可以看到::before :before ::after :after,但是没有使用过,今天查了些资料,终于知道了他们的关 ...
- NSNotificationCenter(通知)与Key-Value Coding (KVC)与Key-Value Observing (KVO)
NSNotificationCenter //下面是不同类中需要实现的代码 1.[[NSNotificationCenter defaultCenter] addObserver:self selec ...
- 使用Navicat导入导出表的数据做测试(转载)
当我们对MySQL数据库进行了误操作,造成某个数据表中的部分数据丢失时,肯定就要利用备份的数据库,对丢失部分的数据进行导出.导入操作了.Navicat工具正好给我们提供了一个数据表的导入导出功能. 1 ...
- 安装scikit-learn过程记录
环境:Windows 10 X64企业版. 安装python2.7: 官网下载python-2.7.12.amd64.msi安装文件,过程不赘述.安装完成后在PATH环境变量中加入%PYTHON_HO ...