2 shunfurh 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
devmiao   Ds   Rxr 2017.08.27 23:52
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
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
题目: 给定一个正整数n,一定存在若干整数平方和为该正整数,求满足该条件的最小整数个数。平方数为(1,4,9,16......),使其和为n。例如给定n=12,则返回3,因为12=4+4+4;给定n=13,则返回2,因为13=4+9. 解题思路: 1、使用动态规划,维护一个长度为n+1的数组,第i位存储和为i的最少整数个数。则f(i)只与i之前的数组有关。 2、变态解法(四平方和定理),任
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) <译自官方文档>
轮流下棋与宣布获胜者。目前,游戏中一个明显的问题是,只有“X”一个人能玩。现在就解决这个问题。我们默认,“X”执先手。在 Board 组件的构造函数中
CF Round 488C. Two Squares 暴力,几何
题意:分别给出两个矩形的4个顶点,第一个矩形的边平行坐标轴,第二个矩形的边和坐标轴呈45度角.顶点都为整数,并且 -100&amp;lt;=x&amp;lt;=100. 问这两个矩形是否相交.若这两个矩形相交,因为肯定有一个矩形的某个边界落在另一个矩形内, 存在有一个交点为整数点.由于坐标的范围很小, 先求出第二个矩形的边界 在求出其所有的整数点标记即可.#include &amp;lt;bits/stdc++.h&amp;gt...
840. Magic Squares In Grid
给出一个矩阵,判断其中3*3的幻方的数目。
Codeforces #488div.2 - 994C - Two Squares(计算几何入门)
第一个也是很简单就容易判断的是:两个线段一旦相交就一定是YES 然后就是判断不相交但是也是YES的情况了,我们可以这样思考: 依照题意,正方形的点是按时钟顺序给出的,那么在正方形中的点就一定会被头尾依次相连的四个边向量lturn测试给出相同的正负值,所以如果16次测试为相同符号,其中一个正方形就一定在另一个正方形中间。 #include &amp;amp;lt;cstdio&amp;amp;gt; #include &amp;amp;lt...
[leetcode-279]Perfect Squares(java)
问题描述: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13,