USACO 5.1 Starry Night
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)
23In 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.
15
10001000000000010000000
01111100011111000101101
01000000010001000111111
00000000010101000101111
00000111010001000000000
00001001011111000000000
10000001000000000000000
00101000000111110010000
00001000000100010011111
00000001110101010100010
00000100110100010000000
00010001110111110000000
00100001110000000100000
00001000100001000100101
00000001110001000111000

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)
a000a0000000000b0000000This is one possible result for the sample input above. Notice that this output file corresponds to the following picture.
0aaaaa000ccccc000d0dd0d
0a0000000c000c000dddddd
000000000c0b0c000d0dddd
00000eee0c000c000000000
0000e00e0ccccc000000000
b000000e000000000000000
00b0f000000ccccc00a0000
0000f000000c000c00aaaaa
0000000ddd0c0b0c0a000a0
00000b00dd0c000c0000000
000g000ddd0ccccc0000000
00g0000ddd0000000e00000
0000b000d0000f000e00e0b
0000000ddd000f000eee000

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的更多相关文章
- 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 ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- USACO翻译:USACO 2013 DEC Silver三题
USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...
- USACO翻译:USACO 2014 DEC Silver三题
USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...
- USACO翻译:USACO 2012 FEB Silver三题
USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...
- USACO翻译:USACO 2012 JAN三题(3)
USACO 2012JAN(题目三) 一.题目概览 中文题目名称 放牧 登山 奶牛排队 英文题目名称 grazing climb lineup 可执行文件名 grazing climb lineup ...
- USACO翻译:USACO 2012 JAN三题(2)
USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...
- USACO翻译:USACO 2012 JAN三题(1)
USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...
随机推荐
- VS2010 中更改项目名称
Time.vcxproj修改项目名称,主要是通过以下几个步骤就能完成: 修改解决方案的名称. 修改解决项目名称. 修改项目的程序集名称和默认命名空间 替换整个项目或解决方案中的出现该名称的地方. 修改 ...
- JS中浮点数精度误差解决
问题出现 0.1 + 0.2 = 0.30000000000000004 问题分析 对于浮点数的四则运算,几乎所有的编程语言都会有类似精度误差的问题,只不过在 C++/C#/Java 这些语言中已经封 ...
- Openssh版本升级(Centos6.7)
实现前提公司服务器需要进行安全测评,扫描漏洞的设备扫出了关于 openssh 漏洞,主要是因为 openssh的当前版本为5.3,版本低了,而yum最新的openssh也只是5.3,没办法只能到 rp ...
- Zabbix监控PV和UV
Zabbix-server:172.21.97.153 Zabbix-agent(Nginx):172.17.27.61 # Nginx日志如下: # head -3 Syz.access.log w ...
- Python核心编程——Chapter15
正则表达式在脚本语言里是最重要的一部分,这部分的题目真的不容怠慢. 开始这部分的题目的解答! 15.1识别下列字符串:bat,bit,but,hat,hit和hut. >>> imp ...
- mysql修改表操作
一: 修改表信息 1.修改表名 alter table test_a rename to sys_app; 2.修改表注释 alter table sys_application comment '系 ...
- 表单验证插件-validator.js 使用教程
做网站的时候,常常会涉及到各种表单验证.选择一款好用的表单验证插件,会降低表单验证开发的难度.在开发中,我目前使用的表单验证插件是:validator.js. validator.js 是一款轻量的表 ...
- 多校 HDU 6397 Character Encoding (容斥)
题意:在0~n-1个数里选m个数和为k,数字可以重复选: 如果是在m个xi>0的情况下就相当于是将k个球分割成m块,那么很明显就是隔板法插空,不能为0的条件限制下一共k-1个位置可以选择插入隔板 ...
- ubuntu 18.04 安装 flash
下载源码包, 解压 sudo cp Downloads/flash_player_npapi_linux.x86_64/libflashplayer.so /usr/lib/mozilla/plugi ...
- from setuptools import setup ImportError: No module named setuptools【转】
转自:http://www.cnblogs.com/chinacloud/archive/2010/12/24/1915644.html from setuptools import setupImp ...