Hdu 4090 GemAnd Prince (搜索_2010年北京区域赛)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4090
OutPut:
166
36
94
128
896
4096
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <string>
#include <string.h>
using namespace std;
#define MAX 10struct node {int x,y;
}qu[MAX*MAX];
map<string,int> hash;
int mmap[MAX][MAX],ans;
int n,m,K,total;
int dir[8][2] = {{1,0},{1,1},{1,-1},{-1,0},{-1,-1},{-1,1},{0,1},{0,-1}};void Print(int temp[][MAX],int n,int m) {for (int i = n-1; i >= 0; --i)for (int j = 0; j < m; ++j)printf("%d%c",temp[i][j],j==m-1?'\n':' ');
}
void change(int mmap[][MAX],int &n,int &m){int i,j,k[10],tn = 0,tm = 0;for (j = 0; j < m; ++j) {k[j] = 0;for (i = 0; i < n; ++i)if (mmap[i][j]) mmap[k[j]++][j] = mmap[i][j];}for (j = 0; j < m; ++j) if (k[j]) {for (i = 0; i < k[j]; ++i)mmap[i][tm] = mmap[i][j];for (i = k[j]; i < n; ++i)mmap[i][tm] = 0;tm++;if (k[j] > tn) tn = k[j];}n = tn,m = tm;
}
int Ok(int temp[][MAX],int vis[][MAX],int i,int j,int n,int m) {int cnt = 0,k;int head = 0,tail = 0;node cur,next;cur.x = i,cur.y = j;qu[head++] = cur;vis[cur.x][cur.y] = 1;while (tail < head) {cur = qu[tail++];cnt++;for (k = 0; k < 8; ++k) {next.x = cur.x + dir[k][0];next.y = cur.y + dir[k][1];if (next.x >= 0 && next.x < n&& next.y >= 0 && next.y < m&& vis[next.x][next.y] == 0&& temp[next.x][next.y] == temp[i][j]) {qu[head++] = next;vis[next.x][next.y] = 1;temp[next.x][next.y] = 0;}}}temp[i][j] = 0;return cnt >= 3 ? cnt : 0;
}
string GetHash(int temp[][MAX],int n,int m) {string s = "";for (int i = 0; i < n; ++i)for (int j = 0; j < m; ++j)s += temp[i][j] + '0';return s;
}
void mem(int temp[][MAX],int mmap[][MAX],int n,int m) {memset(temp,0,sizeof(temp));for (int i = 0; i < n; ++i)for (int j = 0; j < m; ++j)temp[i][j] = mmap[i][j];
}
int Dfs(int mmap[][MAX],int n,int m) {if (n * m < 3) return 0;int temp[MAX][MAX],i,j;int vis[MAX][MAX],cnt = 0,ans;memset(vis,0,sizeof(vis));for (i = 0; i < n; ++i)for (j = 0; j < m; ++j)if (!vis[i][j] && mmap[i][j]) {mem(temp,mmap,n,m);ans = Ok(temp,vis,i,j,n,m);if (ans >= 3) {ans = ans * ans;int tn = n,tm = m;change(temp,tn,tm);string s = GetHash(temp,tn,tm);if (hash.find(s) == hash.end()) ans += Dfs(temp,tn,tm);else ans += hash[s];if (ans > cnt) cnt = ans;}}hash[GetHash(mmap,n,m)] = cnt;return cnt;
}int main() {int i,j,k;while (scanf("%d%d%d",&n,&m,&K) != EOF) {memset(mmap,0,sizeof(mmap));for (i = n-1; i >= 0; --i)for (j = 0; j < m; ++j)scanf("%d",&mmap[i][j]);hash.clear();printf("%d\n",Dfs(mmap,n,m));}
}
本文ZeroClock原创,但可以转载,因为我们是兄弟。
Hdu 4090 GemAnd Prince (搜索_2010年北京区域赛)相关推荐
- (2015)北京区域赛总结+回忆录
从去年7月跟着学长们入坑,到今年11月去北京比赛,一年多的时间就这样转眼度过,现在坐在电脑面前码字时大脑却一片空白,不知道从何说起.想起去年暑假的时候,每天都是8点多到实验室晚上10点回宿舍,顿顿和学 ...
- 星辰天合获得鲲鹏应用创新大赛 2022 北京区域赛决赛一等奖
2022 年 8 月 30 日,以 "数智未来,因你而来" 为主题的统信创客北京・鲲鹏应用创新大赛 2022 北京区域决赛于北京鲲鹏联合创新中心成功举办,XSKY星辰天合团队的参选 ...
- 2018北京区域赛总结
因为这次北京之行要花费四五天,临行前,我将所有课程的作业都做完了,甚至连回来要上的课的都提前准备了.万万没想到,jsp老师突然说要期中考,这令我心中有些烦躁,有点担心学业会被这次比赛搞砸.犹豫了一下, ...
- 2017 ACM-ICPC 北京区域赛记录
------------------------------------------------------------------------------ 出发日 拖着一个大箱子走是真的累. 下午三 ...
- 2016北京区域赛E UVAlive 7672 题目:What a Ridiculous Election 带约束条件的BFS
这几天做的北京的模拟,当时被这个题给卡住了,自己写的BFS,一直WA,结束后对拍才找到自己的致命错误 自己做的时候直接通过最优情况去推导最有情况,导致自己掉进死胡同了 这里举一个例子,比如变成0103 ...
- 2015北京区域赛 Mysterious Antiques in Sackler Museum 几何基础+思维
题意是,选出三个,看看是否可以凑成一个新的矩形. #include<bits/stdc++.h> using namespace std; struct node { int cnt[2] ...
- 北京区域赛I题,Uva7676,A Boring Problem,前缀和差分
A Boring Problem 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是第iii项的式子: F(i)=(a1+a2+...+ai)k+(a2+...+ai)k+...+( ...
- 2014 北京区域赛 dp
Matt has N friends. They are playing a game together. Each of Matt's friends has a magic number. In ...
- 【区域赛总结】2015ACM-ICPC北京区域赛
not the end,why the end? 总结: 1.中档难度题目突破较少,后面要集中做一些中档难度的题目 2.多打比赛,bc.cf等,专题理论训练+实战
最新文章
- 【正一专栏】齐达内能熬过2018年的春天吗?
- sql java 创建数据库_java动态创建数据库(sql server)
- mybatis下log4j使用
- thinkphp如何增加session的过期时间
- 16重新安装HA0.63
- 这款插件不既有Chrome版【飞秋下载】
- scala学习-Linux命令行运行jar包传入main方法参数
- 成年人的世界,嘴上喊的都是主义,心里装的都是生意
- 数据恢复工程师视角看腾讯云静默损坏事件
- [解决方案]验证码无法显示
- 深度学习自学(八):人脸识别主要场景与算法实现
- 撕掉单词书,每天花10分钟做这件事,英语水平暴涨!
- 关系分析可视化插件-Cytoscape
- 牛客网剑指offer
- 【ZigBee】JN5169 ZigBee3.0设备入网过程
- Oracle安装之后电脑变慢
- 5-2 uniapp 打包 app 自定义开屏页
- STM32 通用GPIO模拟I2C实现
- 学java有前途吗?方兴未艾!
- Java JUC 简介
热门文章
- win10修改和隐藏系统输入法指示器
- 【Qt学习】 一键生成函数注释
- 根据订单号查询并复制一行
- 联发科有没有高端处理器_联发科处理器哪些好 2019联发科处理器排名
- 百度之星Valley Numer
- CAD 批量打印,输出pdf,plt的工具
- mysql ERROR 1265 (01000)故障解决一例
- act考试是什么意思?
- 《Android自定义控件》RulerView,仿唯品会身高、体重等标尺,尺码控件,滑动可修改刻度值
- 14-[LVI-SAM]visual_odometry_callbackAndprocess