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. [应用篇]第一篇 EL表达式入门

    概念 EL表达式:EL 全名为Expression Language,就是为了替代<%= %>脚本表达式. 作用 获取数据: EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的 ...

  2. 使用spring boot访问mongodb数据库

    一. spring boot中传参的方法 1.自动化配置 spring Boot 对于开发人员最大的好处在于可以对 Spring 应用进行自动配置.Spring Boot 会根据应用中声明的第三方依赖 ...

  3. 6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python)

    6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python) Introduction Here’s a situation yo ...

  4. 阮一峰:自适应网页设计(Responsive Web Design)别名(响应式web设计)

    随着3G的普及,越来越多的人使用手机上网. 移动设备正超过桌面设备,成为访问互联网的最常见终端.于是,网页设计师不得不面对一个难题:如何才能在不同大小的设备上呈现同样的网页? 手机的屏幕比较小,宽度通 ...

  5. javascript 高度相关

    //scrollTop; var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop); ...

  6. 说说JavaScript中的事件模型

    1.javascript中为元素添加事件处理程序的方法有以下几种方式,可以为javascript元素添加事件处理程序 (1) 直接将事件处理代码写在html中(2) 定义一个函数,赋值给html元素的 ...

  7. Jetson TX1 安装Kinect驱动

    1.添加Universe源 $ sudo apt-add-repository universe $ sudo apt-get update 2.安装编译工具和依赖项 $ sudo apt-get i ...

  8. Dream------Hadoop--Hadoop HA QJM (Quorum Journal Manager)

    In a typical HA cluster, two separate machines are configured as NameNodes. At any point in time, ex ...

  9. 如何编译和安装libevent【转】

    转自:http://www.open-open.com/lib/view/open1455522194089.html 来自: http://blog.csdn.net/yangzhenping/ar ...

  10. git clone直接提交用户名和密码

    git使用用户名密码clone的方式: git clone http://username:password@remote 例如:我的用户名是abc@qq.com,密码是abc123456,git地址 ...