liveoj 4238 - Area of Polycubes(搜索)
2012-08-19 09:12
435 查看
题意:给出n个3d坐标,每一个坐标代表一个小立方体,问能否成为一个大的连续的多面体,
要求:1,坐标不能和前面的相同。2.,每一个点必须更前面的相连,第一个除外。
思路:这里的立方体个数不多,暴搜就行了。每次碰到边界表面积加1.
要求:1,坐标不能和前面的相同。2.,每一个点必须更前面的相连,第一个除外。
思路:这里的立方体个数不多,暴搜就行了。每次碰到边界表面积加1.
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; int dp[209][209][209]; int re[109][3]; int cnt,ans; int dx[]={0,0,0,0,-1,1}; int dy[]={-1,1,0,0,0,0}; int dz[]={0,0,-1,1,0,0}; void dfs(int x,int y,int z) { if(dp[x][y][z]==0) { ans++; return ; } if(dp[x][y][z]!=1) return ; dp[x][y][z] = 2;cnt++; for(int i=0;i<6;i++) { int tx=x+dx[i],ty=y+dy[i],tz=z+dz[i]; dfs(tx,ty,tz); } } int main() { // freopen("in.txt","r",stdin); int cas,T=1,n; scanf("%d",&cas); while(cas--) { scanf("%d",&n); memset(dp,0,sizeof(dp)); int fig = -1; for(int i=0;i<n;i++) { scanf("%d,%d,%d",&re[i][0],&re[i][1],&re[i][2]); re[i][0]+=105;re[i][1]+=105;re[i][2]+=105; int j; for(j=0;j<6;j++) { if(dp[re[i][0]+dx[j]][re[i][1]+dy[j]][re[i][2]+dz[j]]) break; } if((i&&j>=6&&fig==-1)||dp[re[i][0]][re[i][1]][re[i][2]]) { fig = i; } dp[re[i][0]][re[i][1]][re[i][2]] = 1; }cnt=0;ans=0; if(fig>0) { printf("%d NO %d\n",T++,fig+1); continue; } dfs(re[0][0],re[0][1],re[0][2]); printf("%d %d\n",T++,ans); } return 0; }
相关文章推荐
- Area of Polycubes
- poj 3792 Area of Polycubes (简单模拟)
- poj 3792 Area of Polycubes
- POJ 3792 Area of Polycubes(思维)
- POJ 3792 Area of Polycubes(模拟)
- Area of Polycubes poj 3792
- POJ 3792 Area of Polycubes 解题报告
- 南邮 OJ 1537 G ? Area of Polycubes
- hdu 2762 Area of polycube
- 思维 csu1697 Surface Area of Cubes
- CSU 1697 Surface Area of Cubes (思维)
- code forces 630 P. Area of a Star
- No. 27 - Area of Rectangles
- Exceeded maximum number of retries. Exceeded max scheduling attempts 3 for instance 7d90eb80-29e2-4238-b658-ade407ff9456. Last exception: [u'Traceback (most recent call last):\n', u' File "/usr/lib/py
- Area of a Parallelogram
- UVA 539 The Settlers of Catan(图的搜索)
- zoj2110 Tempter of the Bone 搜索dfs
- Educational Codeforces Round 2 D - Area of Two Circles' Intersection(两圆交面积)
- IOS成长之路-Nsstring中搜索方法rangeOfString
- hdu 4946 Area of Mushroom 计算几何(凸包)