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)
23
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.
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)
a000a0000000000b0000000
This 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 ...
随机推荐
- Spark记录-Scala介绍
Scala是可扩展语言的缩写,是一种混合功能编程语言. 它由Martin Odersky创建. Scala顺利整合面向对象和函数式语言的功能. Scala被编译后在Java虚拟机上运行. 许多现有公司 ...
- bzoj千题计划151:bzoj1131: [POI2008]Sta
http://www.lydsy.com/JudgeOnline/problem.php?id=1131 dp[i]=dp[fa[i]]-son[i]+n-son[i] #include<cst ...
- PHP基础知识之————匿名函数(Anonymous functions)
匿名函数(Anonymous functions),也叫闭包函数(closures),允许 临时创建一个没有指定名称的函数.最经常用作回调函数(callback)参数的值.当然,也有其它应用的情况. ...
- Python练习-time模块
明天的明天的明天,雾草! # 编辑者:闫龙 #显示当前时间三天后是星期几? import time t = time.time()+((24*3600)*3) tl = time.localtime( ...
- 【算法学习】有旋treap
treap是平衡树的一种.与其他平衡树一样,它也能够支持插入和删除,求第k极值等,接下来我们主要探讨有旋treap的实现过程. treap中每个节点要维护其值,左右孩子以及子树大小.父亲要不要写则看你 ...
- 利用Volatility对Linux内存取证分析-常用命令翻译
命令翻译 linux_apihooks - 检查用户名apihooks linux_arp - 打印ARP表 linux_aslr_shift - 自动检测Linux aslr改变 linux_ban ...
- 2 - django-urls路由系统基本使用
目录 1 路由系统(urls控制) 1.1 正则字符串参数 1.2 url的分组 1.2.1 无名分组 1.2.2 有名分组 1.3 URLconf 在什么上查找 1.4 include(路由分发) ...
- 高性能.NET MVC之QMVC!
ASP.NET!这个词代表者一个单词Fat!因为他总是捆绑着太多的太多的类,太多太多的各种功能!你也许会用到,如果你反编译或阅读他们开源的源码,你会不会犹如在大海中找不到方向?不管是Web form ...
- 2018 CCPC网络赛
2018 CCPC网络赛 Buy and Resell 题目描述:有一种物品,在\(n\)个地点的价格为\(a_i\),现在一次经过这\(n\)个地点,在每个地点可以买一个这样的物品,也可以卖出一个物 ...
- Python之内建函数Map,Filter和Reduce
Python进阶 map,filter, reduce是python常用的built-in function. 且常与lambda表达式一起用. 其中: map 形式:map(function_to_ ...