# BZOJ 3234: [Ahoi2013]立方体

Time Limit: 10 Sec
Memory Limit: 64 MB

Description

Input

Output

Sample Input

input 1

1

0 0 0 1 1 1

input 2

2

0 1 0 3 2 1

1 0 0 2 3 1

Sample Output

output 1

6

output 2

22
HINT

1<=N<=200,0<=x_i1,y_i1,z_i1,x_i2,y_i2,z_i2<=200,x_i1<x_i2,y_i1<y_i2,z _i1<z_i2

Source

#### Code####

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<vector>
using namespace std;
#define PA pair<int,int>
{
int s=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+ch-'0';ch=getchar();}
return s*f;
}
int n,f[205][205][205],ans,mx,my,mz;
bool vis[205][205][205];
int dx[6]={-1,1,0,0,0,0},dy[6]={0,0,-1,1,0,0},dz[6]={0,0,0,0,-1,1};
struct pai;
queue<pai>q;int kk;
struct pai
{
int x,y,z;
void dfs()
{
if(vis[x][y][z])return;
if(f[x][y][z])ans++;
else
{vis[x][y][z]=1;
for(int i=0;i<6;i++)
q.push((pai){x+dx[i],y+dy[i],z+dz[i]});
}
kk++;
}
};
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int x1,x2,y1,y2,z1,z2;
for(int i=1;i<=n;i++)
f[x1][y1][z1]++;
f[x1][y1][z2]--;
f[x1][y2][z1]--;
f[x2][y1][z1]--;
f[x2][y2][z1]++;
f[x2][y1][z2]++;
f[x1][y2][z2]++;
f[x2][y2][z2]--;
mx=max(mx,x2);
my=max(my,y2);
mz=max(mz,z2);
}
for(int i=1;i<=mx+1;i++)
for(int j=1;j<=my+1;j++)
for(int k=1;k<=mz+1;k++)
f[i][j][k]=f[i][j][k]+f[i-1][j][k]+f[i][j-1][k]+f[i][j][k-1]-f[i-1][j-1][k]-f[i-1][j][k-1]-f[i][j-1][k-1]+f[i-1][j-1][k-1];
for(int i=0;i<=mx+2;i++)
for(int j=0;j<=my+2;j++)
for(int k=0;k<=mz+2;k++)
if(i==0||j==0||k==0||i==mx+2||j==my+2||k==mz+2)
vis[i][j][k]=1;
for(q.push((pai){1,1,1});!q.empty();)
{pai x=q.front();q.pop();
x.dfs();
}
printf("%d\n",ans);
//fclose(stdin);
//fclose(stdout);
return 0;
}



posted on 2016-03-12 21:23  wuyuhan  阅读(232)  评论(0编辑  收藏  举报