poj1175 搜索+hash
来源:互联网 发布:java aes 256 cbc 编辑:程序博客网 时间:2024/06/15 04:51
题意:划分,对称或旋转相同的算同一种
分析:bfs划分区间,hash平均距离
#include <cstdio>#include <algorithm>#include <queue>#include <map>#include <cstring>#include <cmath>#include <iostream>using namespace std;#define maxn 105*105int way[8][2]={1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};int mp[105][105];map<int,long long int >M;map<int,char>IC;int ID;int n,m;int num;struct node{ int x,y;};int check(node s){ if( mp[s.x][s.y] == 1 )return 1; return 0;}node data[maxn];void bfs(int x,int y){ num = 0 ; node s; s.x=x,s.y=y; queue<node>Q; Q.push(s); while( !Q.empty() ){ node e = Q.front(); Q.pop(); mp[e.x][e.y] = ID; data[++num].x = e.x; data[num].y = e.y; for(int i = 0 ; i < 8 ; ++i){ node nx = e; nx.x += way[i][0]; nx.y += way[i][1]; if(check(nx)){ mp[nx.x][nx.y] = ID; Q.push(nx); } } }}void Deal(int x,int y){ double xx = 0; double yy = 0; double tot = 0; bfs(x,y); for(int i = 1 ; i <= num ; ++i){ xx += data[i].x; yy += data[i].y; } xx = xx / num; yy = yy / num ; for(int i = 1 ; i <= num ; ++i){ node e = data[i]; tot += pow(e.x-xx,4) + pow(e.y-yy,4); } M[ID] = (long long int)(tot*1000);}void init(){ M.clear(); ID = 1; IC.clear();}int main(){ while( cin >> m >> n ){ init(); for(int i = 1 ; i <= n ; ++i) for(int j = 1 ; j <= m ; ++j) scanf("%1d",&mp[i][j]); for(int i = 1 ; i <= n ; ++i) for(int j = 1 ; j <= m ; ++j){ if( mp[i][j] == 1 ){ ID++; Deal(i,j); } } int k = 0; for(int i = 2 ; i <= ID ; ++i){ if( 'a' <= IC[i] && IC[i] <= 'z')continue; IC[i] = 'a' + k++; for(int j = i + 1 ; j <= ID ; ++j){ if( M[i] == M[j] ){ IC[j] = IC[i]; } } } for(int i = 1 ; i <= n ; ++i){ for(int j = 1 ; j <= m ; ++j){ if( mp[i][j] ){ printf("%c",IC[mp[i][j]]); } else printf("0"); }printf("\n"); } }}
0 0
- poj1175 搜索+hash
- 双向搜索+hash
- hdu6171 双向搜索+hash
- POJ 1840 双向搜索 +Hash
- 用HASH表进行海量数据搜索
- 通过建立hash表快速搜索资源
- 知道hash值如何搜索文件
- poj 3131 双向搜索+hash判重
- UVA 10604 (记忆化搜索 + hash)
- 【CodeVS】1229 数字游戏 开放性 搜索 Hash
- Algorithm:Hash 及 二叉搜索树
- HDU 6046 hash(搜索标识)
- HDU6076(dp+记忆化搜索+hash)
- POJ-1175:Starry Night(搜索+hash)
- usaco 4.4 Shuttle Puzzle(字符hash+搜索)
- hash buckets and chains,对buffer的搜索获取
- uva 704 Colour Hash(隐式图搜索+ 模拟)
- UVALive 3710 Interconnect(记忆化搜索 + hash)
- 2个DIV切换显示
- iOSAPP前台后台切换的处理
- Lua IO库详解
- jQuery六章 使用jQuery操作DOM
- react-native Linking
- poj1175 搜索+hash
- 浅谈JDBC的升级之路
- Usb otg storage 的调试
- nginx php显示空白处理
- Linux 网络接口配置(/etc/network/interfaces)
- iOS中打一个包上传后,iTunes中找不到上传的包的解决方法
- 有个排序后的字符串数组,其中散步着一些空字符串,找出给定字符串的位置
- Python下调用Linux的Shell命令
- iOS实现浮动泡泡功能,悬浮泡泡,windows系统屏幕保护程序的气泡功能(碰撞检测)