UVA 225 剪枝+dfs
来源:互联网 发布:linux send 返回值 编辑:程序博客网 时间:2024/05/21 14:00
//http://acm.hust.edu.cn/vjudge/problem/35587#include <stdio.h>#include <string>#include <cstring>#include <queue>#include <algorithm>#include <functional>#include <vector>#include <sstream>#include <iomanip>#include <math.h>#include <iostream>#include <sstream>#include <time.h>#include <stack>#include <set>#include <map>#include <time.h>#include <bitset>using namespace std;const int MAX=300;const int dX[4]= {1,0,0,-1};const int dY[4]= {0,1,-1,0};const char dD[4]= {'e','n','s','w'};int T,N,M,Cnt;char Ans[50];int G[2*MAX+10][2*MAX+10];bool check(int n,int x,int y,int m){ int cx=x,cy=y; for (int i=1; i<=n; i++) { cx+=dX[m],cy+=dY[m]; if (G[cx+MAX][cy+MAX]==-1) return false; } return true;}void dfs (int n,int x,int y,int last){ if (n==N+1&&x==0&&y==0) { Cnt+=1; for (int i=1; i<=N; i++) cout<<Ans[i]; cout<<'\n'; return; } if (n==N+1) return; for (int i=0; i<4; i++) { if (last==i||last+i==3) continue; if (check(n,x,y,i)) { int nx=x+dX[i]*n,ny=y+dY[i]*n; if (G[nx+MAX][ny+MAX]) continue; G[nx+MAX][ny+MAX]=1; Ans[n]=dD[i]; dfs(n+1,nx,ny,i); G[nx+MAX][ny+MAX]=0; } }}int main(){ cin.sync_with_stdio(false); cin>>T; int a,b; while (T--) { Cnt=0; memset(G,0,sizeof(G)); cin>>N>>M; for (int i=0; i<M; i++) { cin>>a>>b; if (a<MAX&&a>-MAX&&b<MAX&&b>-MAX) G[a+MAX][b+MAX]=-1; } dfs(1,0,0,-1); cout<<"Found "<<Cnt<<" golygon(s).\n\n"; } return 0;}
0 0
- UVA 225 剪枝+dfs
- UVa 225 – Golygons [DFS+剪枝]
- uva--10160+dfs+剪枝
- UVA-11882 bfs + dfs + 剪枝
- uva 10160 Servicing Stations(DFS+剪枝)
- uva 307 Sticks(DFS+ 剪枝)
- UVA 519 Puzzle (II) (dfs + 剪枝)
- UVA 10318 - Security Panel(dfs+剪枝)
- uva 10318 - Security Panel(dfs+剪枝)
- [UVA 307] Sticks (DFS回溯 + 剪枝)
- uva:307 - Sticks(dfs + 剪枝)
- uva 690 - Pipeline Scheduling(dfs+剪枝)
- UVA 10318 - Security Panel dfs 剪枝
- Game Show Math +uva+dfs+剪枝
- 【UVA】10317 - Equating Equations(dfs + 剪枝)
- UVA - 10123 No Tipping 剪枝+dfs
- UVa 140 Bandwidth(DFS 回溯 剪枝)
- UVa 211 - The Domino Effect [DFS剪枝]
- socket 设置非阻塞
- 设计模式之原型模式
- UVA 208 并查集+dfs
- 白话scala系列五 匿名函数分析
- CocoaPods的安装使用及遇到的问题
- UVA 225 剪枝+dfs
- 郑大第九届校赛-正式赛-zzulioj-1812-sort
- Ugly Number
- Struts2简介以及初步搭建配置
- onethink源码success 和error 无法跳转链接
- 使用LeakCanary检测内存泄露
- 【JAVA基础小问题】Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型?
- 06_Elasticsearch 批量获取mget
- 单项散列加密