Starry Night
IOI 98

High up in the night sky, the shining stars appear in clusters of various shapes. A cluster is a non-empty group of neighbouring stars, adjacent in horizontal, vertical or diagonal direction. A cluster cannot be a part of a larger cluster.

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.

 
Figure 1. Eight similar clusters

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.

PROGRAM NAME: starry

INPUT FORMAT

The first two lines contain, respectively, the width W and the height H of a sky map. The sky map is given in the following H lines, of W characters each.

SAMPLE INPUT (file starry.in)

23
15
10001000000000010000000
01111100011111000101101
01000000010001000111111
00000000010101000101111
00000111010001000000000
00001001011111000000000
10000001000000000000000
00101000000111110010000
00001000000100010011111
00000001110101010100010
00000100110100010000000
00010001110111110000000
00100001110000000100000
00001000100001000100101
00000001110001000111000
In this case, the sky map has width 23 and height 15. Just to make it clearer, notice that this input file corresponds to the following picture of the sky.


Figure 2. Picture of the sky

OUTPUT FORMAT

The output file contains the same map as the input file, except that the clusters are marked as described in Task.

There will generally be more than one way to label the clusters with letters. Your program should choose the labeling such that if the entire output file is read as a string, this string will be minimal in the lexicographical ordering.

SAMPLE OUTPUT (file starry.out)

a000a0000000000b0000000
0aaaaa000ccccc000d0dd0d
0a0000000c000c000dddddd
000000000c0b0c000d0dddd
00000eee0c000c000000000
0000e00e0ccccc000000000
b000000e000000000000000
00b0f000000ccccc00a0000
0000f000000c000c00aaaaa
0000000ddd0c0b0c0a000a0
00000b00dd0c000c0000000
000g000ddd0ccccc0000000
00g0000ddd0000000e00000
0000b000d0000f000e00e0b
0000000ddd000f000eee000
This is one possible result for the sample input above. Notice that this output file corresponds to the following picture.


Figure 3. Picture with the clusters marked

Constraints

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

————————————————————————————题解

这道题就是个暴力模拟题

除了恶心人没有别的作用

对称轴我们可以选成50

旋转就是把行的序号=列的序号,列的序号=100-行的序号+1

相似维护就是简单的并查集

真的好恶心啊qwq但是过了还是有一点成就感的,拿最后的数据输出了一下给自己看了看图像的样子是什么

 /*
ID: ivorysi
LANG: C++
TASK: starry
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <string.h>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x7fffffff
#define ivorysi
#define mo 97797977
#define hash 974711
#define base 47
#define pss pair<string,string>
#define MAXN 30005
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
char m[][];
int maze[][],id[][];
int w,h,cnt,fa[],color[],tot,used[];
int dix[]={,-,,,,-,,-};
int diy[]={,,,-,,,-,-};
vector<pii > v[];
pii size[],poi[];
int getfa(int x) {
return fa[x]==x ? x : fa[x]=getfa(fa[x]);
}
int to[],bo[],lf[],ri[];
void dfs(int x,int y) {
id[x][y]=cnt;
if(y<lf[cnt]) lf[cnt]=y;
if(y>ri[cnt]) ri[cnt]=y;
if(x<to[cnt]) to[cnt]=x;
if(x>bo[cnt]) bo[cnt]=x;
v[cnt].push_back(make_pair(x,y));
xiaosiji(i,,) {
if(maze[x+dix[i]][y+diy[i]] && id[x+dix[i]][y+diy[i]]==) {
dfs(x+dix[i],y+diy[i]);
}
}
}
bool circ(int ori,int ch) {
pii t=make_pair(,);
xiaosiji(i,,v[ori].size()) {
int temp=v[ori][i].fi;
v[ori][i].fi=v[ori][i].se;
v[ori][i].se=-temp+;
if(v[ori][i]>t) t=v[ori][i];
}
int inx=poi[ch].fi-t.fi,iny=poi[ch].se-t.se;
xiaosiji(i,,v[ori].size()) {
v[ori][i].fi+=inx;
v[ori][i].se+=iny;
}
sort(v[ori].begin(),v[ori].end());
xiaosiji(i,,v[ori].size()) {
if(v[ori][i]!=v[ch][i]) {
return false;
}
}
return true;
}
void sym(int ori) {
xiaosiji(i,,v[ori].size()) {
v[ori][i].se=-v[ori][i].se;
}
}
void solve() {
scanf("%d%d",&w,&h);
siji(i,,h) {
scanf("%s",m[i]+);
}
siji(i,,h) {
siji(j,,w) {
maze[i][j]=m[i][j]-'';
}
}
memset(to,,sizeof(to));
memset(lf,,sizeof(lf));
siji(i,,h){
siji(j,,w) {
if(maze[i][j]) {
if(id[i][j]==) {
v[++cnt].clear();
dfs(i,j);
size[cnt]=make_pair(bo[cnt]-to[cnt],ri[cnt]-lf[cnt]);
if(size[cnt].fi > size[cnt].se)
swap(size[cnt].fi,size[cnt].se);
}
}
}
}
siji(i,,cnt) fa[i]=i;
siji(i,,cnt) {
sort(v[i].begin(),v[i].end());
pii t=make_pair(,);
xiaosiji(j,,v[i].size()) {
if(v[i][j]>t) t=v[i][j];
}
poi[i]=t;
siji(j,i+,cnt) {
if(getfa(i)!=getfa(j)) {
if(v[j].size() != v[i].size()) {continue;}
if(size[i] != size[j]) {continue;}
siji(k,,){
if(circ(j,i)) {fa[getfa(j)]=getfa(i);break;}
}
sym(j);
siji(k,,){
if(circ(j,i)) {fa[getfa(j)]=getfa(i);break;}
}
}
}
}
siji(i,,cnt) {
if(!used[getfa(i)]) {
used[getfa(i)]=;
color[getfa(i)]=++tot;
}
else {
color[i]=color[getfa(i)];
}
}
siji(i,,h) {
siji(j,,w) {
if(id[i][j]!=) {
printf("%c",color[id[i][j]]+'a'-);
}
else {printf("");}
}
puts("");
}
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("starry.in","r",stdin);
freopen("starry.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}

USACO 5.1 Starry Night的更多相关文章

  1. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  2. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  3. USACO翻译:USACO 2013 NOV Silver三题

    USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...

  4. USACO翻译:USACO 2013 DEC Silver三题

    USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...

  5. USACO翻译:USACO 2014 DEC Silver三题

    USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...

  6. USACO翻译:USACO 2012 FEB Silver三题

    USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...

  7. USACO翻译:USACO 2012 JAN三题(3)

    USACO 2012JAN(题目三) 一.题目概览 中文题目名称 放牧 登山 奶牛排队 英文题目名称 grazing climb lineup 可执行文件名 grazing climb lineup ...

  8. USACO翻译:USACO 2012 JAN三题(2)

    USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...

  9. USACO翻译:USACO 2012 JAN三题(1)

    USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...

随机推荐

  1. 5 Kafka 应用问题经验积累

    16.Kafka 配置文件同步 为了给kafka的进程添加GC日志信息,方便在以后重启的时候,加入GC日志: 修改bin/kafka-server-start.sh: export KAFKA_OPT ...

  2. 用rem做响应式开发

    设置对应的响应式的html rem比例 rem就是根元素(即:html)的字体大小.html中的所有标签样式凡是涉及到尺寸的(如: height,width,padding,margin,font-s ...

  3. 51 nod 1105 第K大的数

    1105 第K大的数 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 数组A和数组B,里面都有n个整数.数组C共有n^2个整数,分别是A[0] * ...

  4. zookeeper系列之:zookeeper简介浅谈

    一.zookeeper的定义 打开zookeeper官网,赫然一行大字,写着:“Apache ZooKeeper致力于开发和维护实现高度可靠的分布式协调的开源服务器”.什么意思呢?就是Apache Z ...

  5. 使用lombok提高编码效率

    通过gettter,setter注解lombok已经帮我们自动生成了getter,setter方法!

  6. IIS 无法显示网页问题

    今天服务器上的项目突然无法访问,之前也碰到过,都是重启服务器解决的,因为重启IIS无效,另外检查发现w3wp.exe进程正常,其他端口及相关的都没什么问题,最后无奈只能想到用重启来解决了,今天又出现这 ...

  7. 基于受限玻尔兹曼机(RBM)的协同过滤

    受限玻尔兹曼机是一种生成式随机神经网络(generative stochastic neural network), 详细介绍可见我的博文<受限玻尔兹曼机(RBM)简介>, 本文主要介绍R ...

  8. 20155202 2016-2017-2 《Java程序设计》第7周学习总结

    20155202 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 世界协调时间:UTC 采用 闰秒修正 Epoch为某特定时代开始,时间轴上某一瞬间 Unix ...

  9. HDU 1263 水果 结构体排序

    解题报告:一个结构体排序的题,用了一个运算符重载,要注意的是不同的地方可能会产相同的水果,一开始没注意. #include<cstdio> #include<cstring> ...

  10. UNIX网络编程 第6章 I/O复用:select和poll函数

    UNIX网络编程 第6章 I/O复用:select和poll函数