hihoCoder太阁最新面经算法竞赛10 register

Ended

Participants:138

Verdict:Accepted
Score:100 / 100
Submitted:2016-07-24 19:20:38

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
#define N 1000
bool region[N][N];
pair<int, int> board[N][N];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int islands;
pair<int, int> sfind(int x, int y)
{
    if (board[x][y].first == x && board[x][y].second == y)
        return make_pair(x, y);
    return board[x][y] = sfind(board[x][y].first, board[x][y].second);
}
bool sunion(int x1, int y1, int x2, int y2)
{
    auto p1 = sfind(x1, y1), p2 = sfind(x2, y2);
    if (p1 == p2)
        return false;
    board[p1.first][p1.second] = p2;
    return true;
}
void build(int x, int y)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX