POJ1175:Starry Night(bfs)
http://poj.org/problem?id=1175
题目解析:
这个题因为数据的原因可以很水的过,但我因为把1e-8写成了1e-9WA了N遍,一直WA,题目意思很简单就是相似图形(就是求旋转的图形,我不会,但在discuss中看到
可以通过求图形的长度来求)另外常识性问题double数据类型不能直接比较相等,需要借助一个小数比较,那个比较的小数题目一般会提示,例如这题就是1e-8,另外就是
这题的数据是在是忒坑了!
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define MIN 1e-8
using namespace std;
int map[][];
char ff[][];
int n,m,tt,v[][];
struct node
{
int x,y;
};
int sum[];
double dis[];
struct node1
{
int x,y;
} s[];
int jx[]= {,,,,,-,-,-};
int jy[]= {-,,,-,,-,,};
void bfs(int xx,int yy)
{
memset(v,,sizeof(v));
queue<node>q;
struct node t,f;
int l=;
s[l].x=xx;
s[l++].y=yy;
t.x=xx;
t.y=yy;
v[t.x][t.y]=;
q.push(t);
while(!q.empty())
{
t=q.front();
q.pop();
for(int i=; i<; i++)
{
f.x=t.x+jx[i];
f.y=t.y+jy[i];
if(map[f.x][f.y]&&v[f.x][f.y]==&&f.x>=&&f.x<n&&f.y>=&&f.y<m)
{
s[l].x=f.x;
s[l++].y=f.y;
v[f.x][f.y]=;
q.push(f);
}
}
}
double count=;
for(int i=; i<l; i++)
{
for(int j=; j<l; j++)
{
count=count+sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)*1.0+(s[i].y-s[j].y)*(s[i].y-s[j].y)*1.0);
}
}
int flag=;
for(int i=; i<tt; i++)
{
if(sum[i]==l&&fabs(dis[i]-count)<MIN)
{
ff[xx][yy]=i+'a';
flag=;
}
}
if(flag==)
{
ff[xx][yy]=tt+'a';
dis[tt]=count;
sum[tt]=l;
tt++;
}
}
int main()
{
char str;
while(scanf("%d%d",&m,&n)!=EOF)
{
tt=;
for(int i=; i<n; i++)
{
getchar();
for(int j=; j<m; j++)
{
scanf("%c",&str);//不知道为什么不能直接输入map[i][j],基础知识太渣了
ff[i][j]=str;
map[i][j]=str-'';
}
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
if(map[i][j])
bfs(i,j);
}
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
printf("%c",ff[i][j]);
}
printf("\n");
}
}
return ;
}
Description
Clusters may be similar. Two clusters are similar if they have the same shape and number of stars, irrespective of their orientation. In general, the number of possible orientations for a cluster is eight, as Figure 1 exemplifies. 
The night sky is represented by a sky map, which is a two-dimensional matrix of 0's and 1's. A cell contains the digit 1 if it has a star, and the digit 0 otherwise.
Given a sky map, mark all the clusters with lower case letters. Similar clusters must be marked with the same letter; non-similar clusters must be marked with different letters. You mark a cluster with a lower case letter by replacing every 1 in the cluster by that lower case letter. The order of allocation of letters depends on the first appearance of different clusters, from top to bottom and from left to right.
Input
0 <= W (width of the sky map) <= 100
0 <= H (height of the sky map) <= 100
0 <= Number of clusters <= 500
0 <= Number of non-similar clusters <= 26 (a..z)
1 <= Number of stars per cluster <= 160
Output
Sample Input
23
15
10001000000000010000000
01111100011111000101101
01000000010001000111111
00000000010101000101111
00000111010001000000000
00001001011111000000000
10000001000000000000000
00101000000111110010000
00001000000100010011111
00000001110101010100010
00000100110100010000000
00010001110111110000000
00100001110000000100000
00001000100001000100101
00000001110001000111000
Sample Output
a000a0000000000b0000000
0aaaaa000ccccc000d0dd0d
0a0000000c000c000dddddd
000000000c0b0c000d0dddd
00000eee0c000c000000000
0000e00e0ccccc000000000
b000000e000000000000000
00b0f000000ccccc00a0000
0000f000000c000c00aaaaa
0000000ddd0c0b0c0a000a0
00000b00dd0c000c0000000
000g000ddd0ccccc0000000
00g0000ddd0000000e00000
0000b000d0000f000e00e0b
0000000ddd000f000eee000
Hint

Notice that this sample output corresponds to the following picture.

Source
POJ1175:Starry Night(bfs)的更多相关文章
- BFS广搜题目(转载)
BFS广搜题目有时间一个个做下来 2009-12-29 15:09 1574人阅读 评论(1) 收藏 举报 图形graphc优化存储游戏 有时间要去做做这些题目,所以从他人空间copy过来了,谢谢那位 ...
- [USACO5.1]夜空繁星Starry Night
题目背景 高高的星空,簇簇闪耀的群星形态万千.一个星座(cluster)是一群连通的星组成的非空连通星系,这里的连通是指水平,垂直或者对角相邻的两个星星.一个星座不能是另一个更大星座的一部分, 星座可 ...
- 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)
图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...
- 【BZOJ-1656】The Grove 树木 BFS + 射线法
1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 186 Solved: 118[Su ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- Sicily 1215: 脱离地牢(BFS)
这道题按照题意直接BFS即可,主要要注意题意中的相遇是指两种情况:一种是同时到达同一格子,另一种是在移动时相遇,如Paris在(1,2),而Helen在(1,2),若下一步Paris到达(1,1),而 ...
- Sicily 1048: Inverso(BFS)
题意是给出一个3*3的黑白网格,每点击其中一格就会使某些格子的颜色发生转变,求达到目标状态网格的操作.可用BFS搜索解答,用vector储存每次的操作 #include<bits/stdc++. ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
随机推荐
- DWORD类型
INT 代表int,DWORD 代表 unsigned longint会随着机器位数的不同而发生变化,比如在16位机上为16为,在32位机上为32位,在64位机上为64位.看看最原始的定义就知道了. ...
- centos6.5 开发环境部署(nignx1.7.10+php5.4.38+mysql+ftp)
一些命令和规则以及准备 本次流程再 DigitalOcean上的vps上通过 查看是否已经安装 rpm -qa | grep nginx 删除安装 #普通删除模式 rpm -e nginx #强力删除 ...
- Oracle Apex 有用笔记系列 2 - 文件上传管理
1. 页面设计 页面A有若干region, 当中一个region用于文件列表管理(包含显示,下载.删除).如图A. 在页面A有一button,点击它会调用页面B,页面B负责文件上传.如图B. 图A 图 ...
- hasattr() 、getattr() 、setattr()
hasattr(object, name) :用于判断一个对象中是否有指定的属性或方法,如果存在返回 True,否则返回 False getattr(object, name, [default]) ...
- oracle查锁表
查锁表 select LOCK_INFO.OWNER || '.' || LOCK_INFO.OBJ_NAME as OBJ_NAME, -- 对象名称(已经被锁住) LOCK_INFO.SUBOBJ ...
- 点击一个textView里的link导航至程序内可返回的自定义webView
1,在AppDelegate.h里定义一个 id currentViewController; 在AppDelegate.m里 @implementation UIApplication (Priva ...
- mysql增删改查基本语句
mysql的增删改查属于基本操作,又被简称CRUD,其中删用的较少,毕竟这个功能给用户是是非常危险的,就是客户删除的数据也没有真正的删除,其中查询是十分常用的. 1 mysql数据库增加:create ...
- 《转》python学习(5)--数据类型
转自 http://www.cnblogs.com/BeginMan/archive/2013/06/08/3125876.html 一.标准类型函数 cmp():比较大小 str():转换为字符串 ...
- 日请求亿级的QQ会员AMS平台PHP7升级实践
版权声明:本文由PHP7升级项目组原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/74 来源:腾云阁 https://www ...
- Android 判断当前是否在跑monkey测试
/** * Returns true if Monkey is running. */ public static boolean isMonkeyRunning() { ...