题意:给一副扑克牌,52张,从左往右一张张排列,然后从左往右遍历,如果该牌和左边第一张牌或左边第三张牌相匹配,那么就将这张牌移到被匹配的牌上,而且只能移动每堆牌最上面一张。2张牌匹配条件是数值相同或花色相同。每当移过一张牌后,应检查牌堆,看有没有其他能往左移动的,如果没有,遍历下一个,直到不能移动牌为止。根据题意:应先比较左边第三张,在比较左边第一张。
解题思路:我用的是数组模拟,开60*60的数组,表示有60堆,每堆60张,再开60的数组,表示每堆牌数。从第二堆开始比较,如果能匹配,把这张牌尽可能往左移,然后再从第二堆开始一直到当前这堆,如果没有能移动的了,就从第三堆开始......
Memory: 400K Time: 0MS
#include <stdio.h>
#include <string.h>
using namespace std;
char a[60][60][5];//牌堆
int v[60];//每堆牌数
bool match(char *a,char *b)//匹配
{
if(a[0]==b[0] || a[1]==b[1]) return true;
else return false;
}
int adjust()
{
int n=52;
while(1
Memory: 400K Time: 0MS
#include <stdio.h>
#include <string.h>
using namespace std;
char a[60][60][5];//牌堆
int v[60];//每堆牌数
bool match(char *a,char *b)//匹配
{
if(a[0]==b[0] || a[1]==b[1]) return true;
else return false;
}
int adjust()
{
int n=52;
while(1