shunfurh 于 2017.08.27 11:46 提问

Gem Squares

Problem Description
You are given a board with 8×8 squares. In each square, there can be either a colored gem or no gem at all. Gems with different colors are represented by different integers. It is guaranteed that there are no more than two consecutive gems with the same color either in a row or in a column, and that there is not any gem above a blank square.

........
........
........
........
........
..43366.
..121556
44212335

For two neighboring squares, you can exchange the gems.

........
........
........
........
........
..43366.
..111556
44222335

If there are more than two consecutive gems with the same color in a row or in a column after exchange, these gems will be taken away simultaneously. Note that a gem could be counted both in its row and in its column; refer to the sample test cases for details.

........
........
........
........
........
..43366.
.....556
44...335

If there is no gem under a gem, the gem will fall to the square below.

........
........
........
........
........
.....66.
.....556
44433335

After all gems have fallen down to the lowest place, the procedure will be repeated. If there are more than two gems with the same color in a row or in a column, these gems will be taken away simultaneously. Then some gems will fall to the squares below, if there are no gems under those gems.

........
........
........
........
........
.....66.
.....556
.......5

........
........
........
........
........
........
.....666
.....555

........
........
........
........
........
........
........
........

The procedure will be repeated until there is no gem that can be taken away.

Given a board with 8*8 squares, you task is to determine whether all gems can be taken away by a single exchange or not.

1个回答

devmiao      2017.08.27 23:52

699. Falling Squares
On an infinite number line (x-axis), we drop given squares in the order they are given. The i-th square dropped (positions[i] = (left, side_length)) is a square with the left-most point being pos
【LeetCode】Perfect Squares 解题报告
Perfect Squares[LeetCode]https://leetcode.com/problems/perfect-squares/Total Accepted: 15606 Total Submissions: 53625 Difficulty: MediumQuestion Given a positive integer n, find the least number of p
C. Two Squares
C. Two Squarestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two squares, one with sides parallel to the coordinate axes, and anothe...
LeetCode--279. Perfect Squares（完美平方）Python

leetcode 699. Falling Squares
699. Falling SquaresOn an infinite number line (x-axis), we drop given squares in the order they are given.The i-th square dropped (positions[i] = (left, side_length)) is a square with the left-most p...
React 实现井字棋游戏 (tic-tac-toe) 教程 (4) <译自官方文档>

CF Round 488C. Two Squares 暴力,几何

840. Magic Squares In Grid

Codeforces #488div.2 - 994C - Two Squares(计算几何入门)

[leetcode-279]Perfect Squares(java)