poj1623 Squadtrees
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
需要求出按题目要求建四叉树所需的结点个数,和压缩后的四叉树的结点个数(压缩即只要将相同的子树只取一颗即可),在此,我用string表示一颗子树。
读取好数据之后,直接dfs一遍即可
poj题目链接:http://poj.org/problem?id=1623
shuoj题目链接:http://202.121.199.212/JudgeOnline/problem.php?id=1701
/*********************************
* Built using CHelper plug-in
* Actual solution is at the top
* @author xyiyy @ http://www.cnblogs.com/fraud/
*********************************/ #include <iostream>
#include <cstring>
#include <map>
#include <cstdio>
using namespace std;
int number[];
char a[][];
int col,row;
map<string,int>Map;
int flag;
int ans;
string dfs(int len,int x,int y,int deep,int &temp)
{
string s="\0";
if(len==)return s+a[x][y];
if(len==)
{
s=dfs(len/,x,y,deep+,temp)+dfs(len/,x,y+len/,deep+,temp)
+dfs(len/,x+len/,y,deep+,temp)+dfs(len/,x+len/,y+len/,deep+,temp);
int l=s.length();
bool flag0=,flag1=;
for(int i=;i<l;i++)
{
if(s[i]=='')flag0=;
else flag1=;
}
if(flag1&&flag0)
{
temp=;Map[s]++;
if(Map[s]==)ans+=;
}
else if(flag1){temp=;}
else {temp=;}
}
else
{
flag=;
string s1="\0";
s=dfs(len/,x,y,deep+,temp);
int flag0=,flag1=;
int ret=;
if(temp>)
ret+=temp;
else if(temp)flag1++;
else flag0++;
if(temp==)s1=s1+"";
else if(temp)s1=s1+"";
s=s+dfs(len/,x,y+len/,deep+,temp);
if(temp>)
ret+=temp;
else if(temp)flag1++;
else flag0++;
if(temp==)s1=s1+"";
else if(temp)s1=s1+"";
s=s+dfs(len/,x+len/,y,deep+,temp);
if(temp>)
ret+=temp;
else if(temp)flag1++;
else flag0++;
if(temp==)s1=s1+"";
else if(temp)s1=s1+"";
s=s+dfs(len/,x+len/,y+len/,deep+,temp);
if(temp>)
ret+=temp;
else if(temp)flag1++;
else flag0++;
if(temp==)s1=s1+"";
else if(temp)s1=s1+"";
if(flag0==){temp=;s="";}
else if(flag1==){temp=;s="";}
else if(flag0+flag1==)
{
s=s1;
temp=;
Map[s]++;
if(Map[s]==)ans+=;
}
else
{
ret+=flag0+flag1;
temp=ret;
Map[s]++;
if(Map[s]==)
{
ans+=flag0+flag1;
}
} }
return s;
}
int main()
{
ios::sync_with_stdio(false);
number[]=;
int n,m;
//freopen("a.in","r",stdin);
for(int i=;i<;i++)number[i]=number[i-]*;
while(cin>>n>>m&&(n||m))
{
ans=;
row=n,col=m;
int id=;
while(number[id]<n||number[id]<m)id++;
row=col=number[id];
for(int i=;i<row;i++)
{
for(int j=;j<col;j++)
a[i][j]='';
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>a[i][j];
}
}
Map.clear();
int temp=;
string s=dfs(row,,,,temp);
if(temp==||temp==)ans=;
map<string,int>::iterator it;
int ans1=,ans2=; for(it=Map.begin();it!=Map.end();it++)
{
ans++;
} if(temp==)temp=;
cout<<temp<<" "<<ans<<endl;
}
}
poj1623 Squadtrees的更多相关文章
随机推荐
- Apache服务器安装配置(win版)
登录http://httpd.apache.org/download.cgi 这个地址,找到2.4.10,如下图位置: 2 进入如下界面后,选择第一项ApacheHaus,这是个第三方下载平台,在它的 ...
- HTML/CSS代码片段
内容简介:本文收集了我常用的CSS代码片段! *reset @charset "utf-8"; /* reset */ body, dl, dd, h1, h2, h3, h4, ...
- linux下snprintf和sprinf很少被提及的区别
函数原型:int snprintf(char *dest, size_t size, const char *fmt, ...);函数说明: snprintf函数中的第二个参数,size的解释:siz ...
- Codeforces 229D Towers
http://codeforces.com/problemset/problem/229/D 题意:有n(1<=n<=5,000)座塔排在一条直线上,从左到右每个塔的高度分别为hi(1&l ...
- LeetCode_Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- MVC 自定义错误处理
1. Application_Error namespace Libaray.Web{ public class MvcApplication : System.Web.HttpApplication ...
- git:fatal the current branch master has no upstream branch
git push的时候发生上述错误. git push -u "resp" master resp为git仓库的“地址” reference中由解决方案 http://blog.c ...
- Android 有缓存功能的请求封装接口
/* * @Company 浙 江 鸿 程 计 算 机 系 统 有 限 公 司 * @URL http://www.zjhcsoft.com * @Address 杭州滨江区伟业路1号 * @Emai ...
- Xs and Os Referee
Xs and Os Referee 1 def checkio(game_result): 2 winner = 'D' 3 4 for row in game_result: 5 if row[0] ...
- JavaScript面向对象之类的创建
JavaScript对象的定义: 在js中函数极为对象,对象分为二种:对象字变量产生的对象连接到Object.prototype:函数对象连接到Function.prototype 方法:当一个函数被 ...