//本来写了个和1021相同的HASH,但没过,于是,抱着侥幸的心理,把它变成距离的四次方,
//我就呵呵了。。。
//这个题,完全靠概率。当然了,如果是把图翻转来比较,也是可以的。但好像很麻烦。。 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
const int MAX=;
const int MOD=;
char map[MAX][MAX];
int dir[][]={,,-,,,,,-,,,,-,-,,-,-};
int w,h;
struct cl{
char c;
int val,next;
}clu[];
int hash[];
struct sv{
int x,y;
}save[];
int sa,counted;
int tot;
void dfs(int i,int j){
map[i][j]=''; sa++;
save[sa].x=i; save[sa].y=j;
for(int k=;k<;k++){
int tx=i+dir[k][];
int ty=j+dir[k][];
if(map[tx][ty]==''&&tx>=&&tx<h&&ty>=&&ty<w){
dfs(tx,ty);
}
}
} void calculate(){
int i,j,x,y;
int sum=;
for(i=;i<=sa;i++){
x=save[i].x; y=save[i].y;
for(j=i+;j<=sa;j++){
int dx=abs(x-save[j].x);
int dy=abs(y-save[j].y);
sum=sum+(dx*dx+dy*dy)*(dx*dx+dy*dy);
}
}
int h=sum%MOD; char sure;
if(hash[h]==-){
sure='a'+(++counted);
clu[tot].val=sum;
clu[tot].c=sure;
clu[tot].next=hash[h];
hash[h]=tot++;
}
else{
// bool flag=false;
for(int e=hash[h];e!=-;e=clu[e].next){
if(clu[e].val==sum){
clu[tot].c=clu[e].c;
clu[tot].val=sum;
clu[tot].next=hash[h];
hash[h]=tot++;
sure=clu[e].c;
// flag=true;
break;
}
}
}
for(i=;i<=sa;i++){
map[save[i].x][save[i].y]=sure;
}
} void slove(){
for(int i=;i<h;i++){
for(int j=;j<w;j++){
if(map[i][j]==''){
sa=;
dfs(i,j);
calculate();
}
}
}
} int main(){
int i;
while(scanf("%d%d",&w,&h)!=EOF){
for(i=;i<h;i++)
scanf("%s",map[i]);
counted=-; tot=;
memset(hash,-,sizeof(hash));
slove();
for(i=;i<h;i++){
printf("%s",map[i]);
printf("\n");
}
}
return ;
}

POJ 1175的更多相关文章

  1. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  2. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  3. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  4. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  5. 转载:poj题目分类(侵删)

    转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码)  ...

  6. poj和hdu部分基础算法分类及难度排序

    最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...

  7. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  8. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  9. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

随机推荐

  1. bzoj3555 [Ctsc2014]企鹅QQ——字符串哈希

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3555 很久以前就讲过哈希,但一直没写过题,所以这是哈希第一题! 哈希就是把一个字符串映射成一 ...

  2. 687C

    dp 以前做过 忘了. 想破脑袋不知道怎么设状态 dp[i][j][k]表示选到第i个硬币,当前和为j,能否弄出k dp[i][j][k]|=dp[i-1][j][k]|dp[i-1][j][k-c[ ...

  3. springboot 的一般配置

    import javax.servlet.Filter; import org.springframework.boot.SpringApplication; import org.springfra ...

  4. 页面中word文本框的编辑,两种方式

    大致效果图(对其中的功能可以增减): 实现方法1:调用js <link href="../../platform/js/kindeditor/themes/default/defaul ...

  5. Laravel5.1学习笔记9 系统架构1 请求生命周期 (待修)

    Request Lifecycle Introduction Lifecycle Overview Focus On Service Providers Introduction When using ...

  6. 终极解决VS2015 安装失败问题,如 安装包损坏或丢失

    1.去微软官网下载完成ISO镜像,最好不要在线安装, 打开官方链接 https://www.visualstudio.com/zh-cn/downloads/download-visual-studi ...

  7. CNN:Windows下编译使用Caffe和Caffe2

    用于检测的CNN分为基于回归网络的方法和基于区域+CNN网络的方法,其中基于回归网络的方法典型为YOLO9000,可以兼容使用VGG-Net框架.其中基于区域+CNN网络方法,大量使用了Caffe作为 ...

  8. Memcached 之增删改查命令

    memcache是高性能 ,分布式的内存对象缓存系统,非关系型数据库. 一.增 语法:add  key  flag  expire  length key:值的一个名字 flag:一个标志,是一个正整 ...

  9. 01 Centos安装python3

    Centos安装python3 安装软件的方法有哪几种 1 yum一键安装 2 rpm包安装(太麻烦,不推荐使用) 3 下载源码包,进行编译安装 安装python3的步骤 1.下载python3源码包 ...

  10. localStorage、sessionStorage、cookie

    vue下的全局变量和vuex里的state都是临时变量,页面刷新就都没了.