poj 1069 深搜+建坐标系
来源:互联网 发布:下载淘宝网到电脑桌面 编辑:程序博客网 时间:2024/04/30 09:12
//建立120度坐标系
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int martix[105][105],cut_size[15],n,s,cnt;bool can_cut(int sx,int sy,int num){ int hehe=cut_size[num]; if (sy+2*hehe-2>n*4||sx+hehe-1>n*2) return false; if(sy%2) { for(int i=0;i<hehe;i++) for(int j=0;j<2*i+1;j++) if(martix[sx+i][sy+j]==0) return false; } else { for(int i=0;i<hehe;i++) for(int j=2*i;j<2*hehe-1;j++) if(martix[sx+i][sy+j]==0) return false; } return true;}void cut(int sx,int sy,int num){ int hehe=cut_size[num]; if(sy%2) { for(int i=0;i<hehe;i++) for(int j=0;j<2*i+1;j++) martix[sx+i][sy+j]=0; } else { for(int i=0;i<hehe;i++) for(int j=2*i;j<2*hehe-1;j++) martix[sx+i][sy+j]=0; }}void recut(int sx,int sy,int num){ int hehe=cut_size[num]; if(sy%2) { for(int i=0;i<hehe;i++) for(int j=0;j<2*i+1;j++) martix[sx+i][sy+j]=1; } else { for(int i=0;i<hehe;i++) for(int j=2*i;j<2*hehe-1;j++) martix[sx+i][sy+j]=1; }}bool dfs(int sx,int sy){ if(sx>2*n) return true; if(sy>4*n) return dfs(sx+1,1); if(martix[sx][sy]==0) { int j; for (j=sy+1;j<=4*n;j++) if (martix[sx][j]) break; return dfs(sx,j); } for(int i=0;i<cnt;i++) { if(can_cut(sx,sy,i)) { cut(sx,sy,i); if(dfs(sx,sy+1)) return true; recut(sx,sy,i); } else break; } return false;}void solve(){ int i,fllag[15]={0},j; for(i=0;i<s;i++) if(n%cut_size[i]==0) { printf("YES\n"); return; } sort(cut_size,cut_size+s); for(i=s-1;i>=0&&cut_size[i]>n;i--); s=i+1; for(i=0;i<s;i++) for(j=i+1;j<s;j++) if(cut_size[j]%cut_size[i]==0) fllag[j]=1; for(i=cnt=0;i<s;i++) if(!fllag[i]) cut_size[cnt++]=cut_size[i]; memset(martix,0,sizeof(martix)); for(i=1;i<=n;i++) for(j=1;j<=2*n-1+2*i;j++) martix[i][j]=1; for(i=n+1;i<=2*n;i++) for(j=(i-n)*2;j<=4*n;j++) martix[i][j]=1; if(dfs(1,1)) printf("YES\n"); else printf("NO\n");}int main(){ int t,i; scanf("%d",&t); while(t--&&scanf("%d%d",&n,&s)!=EOF) { for(i=0;i<s;i++) scanf("%d",cut_size+i); solve(); } return 0;}
0 0
- poj 1069 深搜+建坐标系
- POJ 2354 大地坐标系
- poj-1807-Bee Breeding-坐标系
- poj 2632 Crashing Robots&&POJ 1573 Robot Motion 【建坐标系的问题】
- poj 2536 二分图(坐标系中的)
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 坐标系
- 左手坐标系 + 右手坐标系
- 屏幕坐标系,世界坐标系
- 右手坐标系、左手坐标系
- 问题五十九:怎么求一元六次方程在区间内的所有不相等的实根(3)——修正一个问题
- vs环境配置属性介绍
- Android 多文件上传
- ganglia监控的数据 rrd数据文件
- 程序
- poj 1069 深搜+建坐标系
- 微信小程序---第一天
- 【基础算法】M叉树的遍历问题(BZOJ1185)
- 在Ubuntu 14.10下安装Lua 5.2出错的解决
- 线性表——顺序实现java
- Hadoop那些事儿(二)---MapReduce开发环境搭建
- SpringMVC 无法访问到指定jsp页面可能的原因
- java异常语句中catch,finally的执行顺序
- 树状数组