usaco5.1.2 Starry Night

WSL2新手避坑:刚装好就git clone失败?别急着改代理,先检查这两个文件 本文针对WSL2新手在安装后立即遇到git clone失败的问题,提供了深度排查指南。重点检查/etc/resolv.conf和/etc/hosts两个关键文件的配置错误,涵盖DNS解析、SSH认证和HTTP协议适配等解决方案,帮助开发者快速解决WSL2环境下的Git连接问题。 阅读详情

一 原题

Starry Night
IOI 98

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

Clusters may be similar. Two clusters are similar if they havethe 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
Figure 1. Eight similar clusters

The night sky is represented by a sky map, which is a two-dimensionalmatrix 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-similarclusters must be marked with different letters.

You mark a cluster with a lower case letter by replacing every 1 inthe cluster by that lower case letter.

PROGRAM NAME: starry

INPUT FORMAT

The first two lines contain, respectively, the width W andthe heightH of a sky map. The sky map is given in the followingH lines, ofW 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 itclearer, notice that this input file corresponds to the followingpicture of the sky.

Figure 2. Picture of thesky
Figure 2. Picture of the sky

OUTPUT FORMAT

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

There will generally be more than one way to label the clusters withletters. Your program should choose the labeling such that if theentire output file is read as a string, this string will be minimal inthe 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 thisoutput 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


二 分析

水水的I。先求出所有的联通块,再判断联通块是否形状相同。


三 代码

运行结果:

USER: Qi Shen [maxkibb3]
TASK: starry
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 4252 KB]
   Test 2: TEST OK [0.000 secs, 4252 KB]
   Test 3: TEST OK [0.000 secs, 4252 KB]
   Test 4: TEST OK [0.000 secs, 4252 KB]
   Test 5: TEST OK [0.000 secs, 4252 KB]

All tests OK.

YOUR PROGRAM ('starry') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.

AC代码:

/*
ID:maxkibb3
LANG:C++
PROB:starry
*/

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

const int MAXH = 105;
const int MAXW = 105;
const int MAXC = 505;

int H, W;
char Map[MAXH][MAXW];
int Vis[MAXH][MAXW];
int Cluster_num;
int Flag[MAXC];
int Flag_num;
int dx[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
				{0, 1}, {1, -1}, {1, 0}, {1,1}};

struct Coor {
	int x, y;

	bool operator < (const Coor &obj) const {
		if(obj.x == x) return y < obj.y;
		return x < obj.x;
	}

	bool operator == (const Coor &obj) const {
		if(x != obj.x || y != obj.y) return false;
		else return true;
	}

	Coor operator - (const Coor &obj) const {
		Coor ret;
		ret.x = x - obj.x;
		ret.y = y - obj.y;
		return ret;
	}
};

Coor mk_coor(int _x, int _y) {
	Coor ret;
	ret.x = _x, ret.y = _y;
	return ret;
}

struct Cluster {
	vector<Coor> stars;

	bool operator == (const Cluster &obj) const {
		if(stars.size() != obj.stars.size()) return false;
		Coor delta = stars[0] - obj.stars[0];
		for(int i = 1; i < stars.size(); i++) {
			Coor tmp = stars[i] - obj.stars[i];
			if(tmp == delta) continue;
			else return false;
		}
		return true;
	}

	Cluster rotate() {
		Cluster ret;
		for(int i = 0; i < stars.size(); i++)
			ret.stars.push_back(mk_coor(stars[i].y, -stars[i].x));
		return ret;
	}

	Cluster flip() {
		Cluster ret;
		for(int i = 0; i < stars.size(); i++)
			ret.stars.push_back(mk_coor(stars[i].x, -stars[i].y));
		return ret;
	}

	void star_sort() {
		sort(stars.begin(), stars.end());
	}
}Clusters[MAXC];

void init() {
	scanf("%d%d", &W, &H);
	for(int i = 0; i < H; i++)
		scanf("%s", Map[i]);
}

void dfs(int _x, int _y) {
	Vis[_x][_y] = Cluster_num;
	Clusters[Cluster_num - 1].stars.push_back(mk_coor(_x, _y));
	for(int i = 0; i < 8; i++) {
		int x = _x + dx[i][0];
		int y = _y + dx[i][1];
		if(x < 0 || x >= H || y < 0 || y >= W)
			continue;
		if(Map[x][y] == '0')
			continue;
		if(Vis[x][y] != 0)
			continue;
		dfs(x, y);
	}
}

void lable() {
	for(int i = 0; i < H; i++)
		for(int j = 0; j < W; j++) {
			if(Vis[i][j] != 0) continue;
			if(Map[i][j] == '0') continue;
			Cluster_num++;
			dfs(i, j);
		}
}

void merge() {
	for(int i = 0; i < MAXC; i++) Flag[i] = -1;
	for(int i = 0; i < Cluster_num; i++) {
		if(Flag[i] != -1) continue;
		Flag[i] = Flag_num++;
		vector<Cluster> c;
		Cluster base = Clusters[i];
		for(int j = 0; j < 4; j++) {
			base.star_sort();
			c.push_back(base);
			Cluster tmp = base.flip();
			tmp.star_sort();
			c.push_back(tmp);
			base = base.rotate();
		}
		for(int j = i + 1; j < Cluster_num; j++) {
			if(Flag[j] != -1) continue;
			for(int k = 0; k < 8; k++) {
				if(Clusters[j] == c[k]) {
					Flag[j] = Flag[i];
					break;
				}
			}
		}
	}
	for(int i = 0; i < Cluster_num; i++) {
		Cluster c = Clusters[i];
		for(int j = 0; j < c.stars.size(); j++) {
			Map[c.stars[j].x][c.stars[j].y] = (char)('a' + Flag[i]);
		}
	}
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) printf("%c", Map[i][j]);
		printf("\n");
	}
}

void solve() {
	lable();
	merge();
}

int main() {
	freopen("starry.in", "r", stdin);
	freopen("starry.out", "w", stdout);
	init();
	solve();
	return 0;
}


VSCode插件全攻略:5分钟搞定Mermaid流程图实时预览(含常见报错解决) 本文提供了一份详细的VSCode插件实战指南,帮助开发者快速配置Mermaid流程图实时预览环境。文章涵盖核心插件选择、高效工作流搭建,并重点解决了图表渲染失败、样式异常等常见报错问题,旨在提升技术文档的编写效率与可视化质量。 阅读详情

相关推荐

硬件开发流程

研发流程在一个有一定规模的企业中起到了非常重要的作用,也是一个产品或者项目成功量产出货依赖的平台体系,作为工程师如果想要走的更远,就必须了解流程体系,了解如何对产品的开发质量进行更好的管控。...

weixin_44126796的博客 8376

USACO5.1.2 Starry Night(starry)

数据不大,但细节要注意。这道题的基本方法就是Floodfill,找到所有的连通块,把全等的连通块标识起来。 寻找全等连通块的方法很多,我的方法是把每个连通块散列存储起来。找到一个新的连通块的时候把它和旋转对称变换所得8个图形分别进行散列,然后在哈希表中查找是否出现过。如果出现过,新的连通块与以前的全等。如果没有出现,则找到了一个新的连通块,标识并存储即可。 /* PROB: starr

xsy_victory的专栏 477

主成分分析(PCA)和局部线性嵌入(LEE)原理详解

从KNN谈“维度灾难”,介绍线性降维PCA和局部线性嵌入LLE 这两种降维方法的原理

superzzx0920的博客 5616

[USACO5.1]夜空繁星Starry Night

题目背景高高的星空,簇簇闪耀的群星形态万千。一个星座(cluster)是一群连通的星组成的非空连通星系,这里的连通是指水平,垂直或者对角相邻的两个星星。一个星座不能是另一个更大星座的一部分, 星座可以相似(similar)。如果两个星座有相同的形状,而且包括相同数目的星体,那么不管其方向性如何,就算相似。一般而言,星座可能的方向有八个,如图1所示。题目描述夜空可以表示为一份天体图(sky map)...

蒟蒻QMQ 502

Openharmony 命令行工具hdc的获取与安装

OpenHarmony实战:命令行工具hdc安装应用指南_hdc工具-优快云博客t=N7T8。

Devlin_的博客 1万+

UsualToolCMS-验证码绕过漏洞复现

本文以UsualToolCMS为靶场,复现了验证码绕过漏洞

小小小屿屿屿的博客 918

洛谷 P2749 [USACO5.1]夜空繁星Starry Night

题目背景 高高的星空,簇簇闪耀的群星形态万千。一个星座(cluster)是一群连通的星组成的非空连通星系,这里的连通是指水平,垂直或者对角相邻的两个星星。一个星座不能是另一个更大星座的一部分, 星座可以相似(similar)。如果两个星座有相同的形状,而且包括相同数目的星体,那么不管其方向性如何,就算相似。一般而言,星座可能的方向有八个,如图1所示。 题目描述 夜空可

苦鬼·。 720

扩增子分析|溯源分析在R中的复现:跟着Nature系列文章利用FEAST溯源分析包追溯微生物群落的起源

溯源分析由Liat Shenhav等人在2019年发表在Nature Methods杂志,他们开创的一种分析微生物群落组成结构的方法,通过量化不同微生物样本(来源)在目标微生物群落(汇)中的比例或分数识别微生物群落的潜在来源。该方法自发表以来受到微生物学界广泛关注,该论文截止2024年10月9日已经被引289次,是领域内高被引论文,该方法已经成为Nature,cell系列文章高度关注的方法。

weixin_46814750的博客 3433

usaco 5.1 Starry Night(BFS+枚举)

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 diagon

志当存高远 1464

【GB28181】wvp-GB28181-pro部署安装教程(Ubuntu平台)

初始环境安装。

废人一枚的博客 5080

深入解析基于Fluent的蒸发冷凝相变UDF程序及其在重力热管液体蒸发冷凝变化计算中的应用

ANSYS Fluent是一款功能强大的CFD软件,广泛应用于流体流动、传热、化学反应和多相流等领域的数值模拟。Fluent提供了丰富的物理模型和求解器,支持用户自定义函数(UDF)以扩展其功能,实现更为复杂和特定的模拟需求。UDF是用C语言编写的程序,允许用户在Fluent中自定义物理模型、边界条件、源项等,以实现特定的模拟需求。在处理复杂的相变过程、非均匀物性参数或特定的热传导机制时,UDF提供了极大的灵活性和扩展性。

qq_38334677的博客 1265

【USACO5-1-2】夜空繁星Starry Night 模拟

题目判断是否相似的方法是将每两点的距离加起来#include&lt;iostream&gt; #include&lt;algorithm&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;cmath&gt; #include&lt;cctype&gt; using namespace std; char res[505][...

Mininda 591

企业合规审查系统开发实战:基于知识图谱与深度学习的智能引擎构建(附完整Python代码)

动态合规监测:实时追踪法规变化并更新知识库智能合约审计:区块链智能合约的自动合规检查跨域知识融合:整合财务、法律、业务多维度数据可解释性增强:基于Attention机制生成合规审查依据。

理论都是虚的,代码才是王道。 456

C++——【USACO 5.1.2】——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 diagon

McDonnell_Douglas的博客 588

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

P2749 [USACO5.1]夜空繁星Starry Night

P2749 [USACO5.1]夜空繁星Starry Night 超大模拟 1.扫联通块(八个方向拓展) 2.去重 3.标记 4.输出 代码好短,跟猪国杀比都不能比 代码: #include<bits/stdc++.h> using namespace std; const int N...

259

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Usaco Training Section 5.1 Starry Night

有很多星座,让你给这些星座编号。(一个星座翻折、旋转得到的星座算同一种) 直接dfs找联通块,最主要的是判同一种。我是把一个星座的每个点排序,用每个点减去第一个点,得出每个点的相对位置,再把每个点的行列坐标连成一个字符串,放入map。这样写起来可能比直接比对好写一些。 #include&lt;bits/stdc++.h&gt; #define ll long long #define u...

Monster的博客 250

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

洛谷P2749 [USACO5.1]夜空繁星Starry Night - 特殊判重 - 搜索

如何确认两个子图即使旋转了仍然是相同的??? 有某个结论:当一张子图内点两两之间距离和相同时,这两张图“相似” 注意是许多距离的和,必须要开根,不开根不是距离。不开根只能应用于两个路径的判断,他不是单判断两个距离之间是否相等,而是判断许多距离相加和许多距离相加之后的和是否相等,平方和和和的平方不是一个东西 还有好多小技巧 比如说我染色的时候不必再走一遍dfs,我可以直接遍历我刚刚记下的点的位...

Zolrk的博客 378

洛谷Luogu-2749 [USACO5.1]夜空繁星Starry Night(DFS+判重) HQG_AC的博客

https://www.luogu.org/problemnew/show/P2749这道题目的意思就是有一个图,上有很多连通块,如果两个连通块能够通过旋转重合,那就认为这两个星系相同,相同的星系标记相同的星系符号,不同的不同。输出星系被标记后的情况算法:DFS求连通块,奇怪方法判重这道题目难就难在判重。但我们还是把整个过程讲一下1.读入,将字符串转化成数组2.枚举每个没有被标记星系标记的星系,D...

Hacheylight 383

洛谷 P2749 [USACO5.1]【夜空繁星Starry Night】

题目背景 高高的星空,簇簇闪耀的群星形态万千。一个星座(cluster)是一群连通的星组成的非空连通星系,这里的连通是指水平,垂直或者对角相邻的两个星星。一个星座不能是另一个更大星座的一部分, 星座可以相似(similar)。如果两个星座有相同的形状,而且包括相同数目的星体,那么不管其方向性如何,就算相似。一般而言,星座可能的方向有八个,如图1所示。 题目描述 夜空可以表示为一份天体图(...

weixin_30567225的博客 158

USACO Section 5.1 Starry Night

题意: zhao'xing'zu

House 781

USACO 5.1 Starry Night

Starry NightIOI 98 High up in the night sky, the shining stars appear in clusters of various shapes. Aclusteris a non-empty group of neighbouring stars, adjacent in horizontal, vertical or dia...

weixin_30915951的博客 214

USACO Starry Night 解题报告

这道题我是用的是最直接的方法。用DFS得到每个cluster,然后zhi

thestoryofsnow的专栏 764

题解Luogu P2749 【[USACO5.1]夜空繁星Starry Night】

HASH判重 我的方法可能比较奇怪 注意一定要判断截出来矩形的形状和图形内部其他图形 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 110, M = 510, dx[8] = {1, 1, 1, -1, -1, -1, 0, 0}, ...

weixin_30457551的博客 130
上一篇: usaco5.1.1 Fencing the Cows
下一篇: usaco5.1.3 Musical Themes
max_kibble
博客等级 码龄11年 2粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值