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. java基础-迭代器(Iterator)与增强for循环

    java基础-迭代器(Iterator)与增强for循环 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Iterator迭代器概述 Java中提供了很多个集合,它们在存储元素时 ...

  2. day10 浅谈面向对象编程

    面向对象编程:第一步找名词,名词是问题域中的. 第二步概括名词设计成类.某些名词可以浓缩包含到其它名词中,成为其属性. 第三步找动词,动词也是问题域中的.   第四步概括动词设计成方法.动作的产生往往 ...

  3. OC中线程安全的单例

    @implementation MySingleton + (instancetype)sharedInstance { static MySingleton* instance = nil; sta ...

  4. python---基础知识回顾(七)迭代器和生成器

    前戏:迭代器和生成器 迭代: 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration). Python的for循环不仅可以用在 ...

  5. memset函数使用详解

    1.void *memset(void *s,int c,size_t n) 总的作用:将已开辟内存空间 s 的首 n 个字节的值设为值 c. 2.例子#include void main(){cha ...

  6. Shell记录-Shell脚本基础(六)

    watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行. 1.命令格式 watch[参数][命令] ...

  7. 监控Elasticsearch的插件【check_es_system】

    监控Elasticsearch的插件推荐  强大的shell脚本 #!/bin/bash ####################################################### ...

  8. iOS AES128 CBC No Padding加密解密

    最近的项目中数据传输用到加密,项目选择了AES128 CBC No Padding加密方式,PHP和Android方面的代码网上太多了.但是唯独没有iOS的,但是也有别的写法,但不是是AES128 C ...

  9. ashx误删后,未能创建类型

    描述 今天,因为临时有事儿,需要去一趟其他城市,项目比较赶.所以只能在车上继续敲代码,倒霉的触摸板让我误删一个ashx一般处理程序.好死不死的这个文件的代码还很长. 我的做法是[垃圾桶]→[还原]→V ...

  10. exec操作文件描述符

    exec命令可以用来替代当前shell:换句话说,并没有启动子shell.使用这一命令时任何环境都将被清除,并重新启动一个shell. 它的一半形式为: exec command 其中,command ...