和大伙伴做题-gym C. Figures
来源:互联网 发布:淘宝卖家工具有哪些 编辑:程序博客网 时间:2024/05/17 05:01
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.
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.
For each test case, print one line with one integer: the number of different figures.
15 51 1 2 2 23 1 3 3 43 4 4 3 45 5 5 2 21 1 1 6 2
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;}
- 和大伙伴做题-gym C. Figures
- figures
- Gym 101128C想法题
- “二马”交锋下一站:线下伙伴和大数据
- 【头条】思杰的新定位:做企业云转型伙伴和使能者
- 我和我的大伙伴们的恒波生活
- 大数据时代,看完我和我的小伙伴都惊呆了
- CodeForces Gym 100114C
- CodeForces Gym 100735C
- Gym 100971C Triangles
- codeforces Gym-101246C
- Codeforces gym 101243 C
- Gym 101164.C
- Gym 101243.C
- Gym 101246.C
- Gym 101482.C
- Cheering Gym-101522C
- Gym 100625C 密文匹配-模拟题-(map)
- 广州电讯-开发部管理培训生(JAVA工程师)面试
- 使用expat开发xml分析器
- Oracle字符串连接的方法
- DataBinder.Eval(Container.DataItem
- ngx_process_options函数详解
- 和大伙伴做题-gym C. Figures
- 误删的照片找回有什么好的办法吗
- 多图详解Spring框架的设计理念与设计模式
- mdss 8x26/8x74 display debug and reading notes(vsync, interface and so on)
- 用expat解析包解析XML文件
- PE文件到内存的映射
- 老生常谈IE兼容性:ie6 javascript:void(0)、IE7 input透明、IE8 jquery动态加载css
- ORA-31655: no data or metadata objects selected for job
- ORA-20001错误