幻想乡麻将游戏
幻想乡麻将游戏
解法
因为 next_permutation 函数。对于一组数据至多要枚举
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int T,a[6];
int main()
{
cin >> T;
while (T--)
{
bool flag=false;
for (int i=1;i<=4;i++)
cin >> a[i];
int P[]={1,2,3,4,5};
do
{
for (int i=0;i<=9;i++)
{
a[5]=i;
if (a[P[0]]-1==a[P[1]] && a[P[1]]==a[P[2]]+1 && a[P[3]]==a[P[4]])
flag=true;
}
}while (next_permutation(P,P+5));
puts(flag?"1":"0");
}
return 0;
}
当然也可以分类讨论,从手速来说好像全排列快一点。