和大伙伴做题-gym C. Figures

C. Figures
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given a map divided into n × m square fields which are colored. We call a subset of fields of the same color a Figure, if it is:

  • in one piece: for every two fields in the Figure, there is a path between them composed of side-adjacent fields belonging to the Figure,
  • maximal: every field from outside the Figure that is adjacent to it has a different color.
Figures A and B are considered identical (they might be colored differently) if you can move A onto B so that every field of B is covered by a field of A and every field of A covers a field from B, without turning the Figure. Calculate the number of different Figures on the given map.

Input

In the first line of input there is an integer z - the number of test cases. Then, z test cases follow.

First line of a test case contains two integers, n and m (1 ≤ n, m ≤ 1000) - number of rows and columns of the map. In next n lines you are given the description of rows on the map: m integers which are nonnegative and no greater than 109. These integers are the colors of fields in the map.

Output

For each test case, print one line with one integer: the number of different figures.

Sample test(s)
input
1
5 5
1 1 2 2 2
3 1 3 3 4
3 4 4 3 4
5 5 5 2 2
1 1 1 6 2
output
5

题意:给定一个图,求出不同形状的块有几种。

思路:我自己想用二维数组记录下拼图形状在插入到set,可是好像set不太支持哦。。。然后大伙伴说可以利用pair保存点,用set保存点集的方法来保存形状,大伙伴实在机智得我整个人都不行了。f@ck。

代码:

#include <stdio.h>
#include <string.h>
#include <set>
using namespace std;
const int d[4][2] = {{0, 1}, {-1, 0}, {1, 0}, {0, -1}};

int t, n, m, g[1005][1005], vis[1005][1005];

typedef pair<int ,int> pi;
set<pi> aa;
set<set<pi> > bb;

void dfs(int x, int y, int num, int a, int b) {
    vis[x][y] = 1;
    aa.insert(make_pair(x - a, y - b));
    for (int i = 0; i < 4; i++) {
	int xx = x + d[i][0];
	int yy = y + d[i][1];
	if (num == g[xx][yy] && !vis[xx][yy] && xx >= 0 && xx < n && yy >= 0 && yy < m) {
	    dfs(xx, yy, num, a, b);
	}
    }
}
int main() {
    scanf("%d", &t);
    while (t --) {
	memset(vis, 0, sizeof(vis));
	bb.clear();
	int count = 0;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++)
	    for (int j = 0; j < m; j ++)
		scanf("%d", &g[i][j]);
	for (int i = 0; i < n; i ++)
	    for (int j = 0; j < m; j ++) {
		if (!vis[i][j]) {
		    aa.clear();
		    dfs(i, j, g[i][j], i, j);
		    if (bb.find(aa) == bb.end()) {
			bb.insert(aa);
			count ++;
		    }
		}
	    }
	printf("%d\n", count);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IoT是物联网(Internet of Things)的缩写,是指通过物理设备和传感器等技术将物理世界与互联网连接起来的概念。Sensor是传感器的意思,是一种能够感知和测量周围环境参数的装置。Gym master是指健身房的管理系统。那么,"IoT-Sensor-Gym-Master"指的是结合物联网、传感器技术和健身房管理系统的项目或产品。 在这个项目中,通过在健身房内部部署各种类型的传感器设备,可以实时感知和监控健身房的各种环境参数以及用户的行为。例如,可以使用体感传感器来监测用户的运动状态,心率传感器来监测用户心率变化,温湿度传感器来监测环境的温度和湿度等等。这些传感器会把收集到的数据通过物联网技术传输到云端服务器进行处理和分析。 在云端服务器上,会有一个健身房管理系统,通过对接收到的传感器数据进行分析和处理,可以提供各种健身相关的功能和服务。例如,可以根据用户的运动状态自动调整健身器材的强度,提供个性化的健身方案;还可以通过用户心率数据实时预警和监控用户的身体状况,保证用户的健康安全;同时,还可以通过温湿度传感器来实时监测健身房的环境,保证用户的舒适度。 总之,"IoT-Sensor-Gym-Master"项目结合了物联网、传感器技术和健身房管理系统的优势,将智能化和个性化服务引入健身领域,为用户提供更好的健身体验和管理服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值