题解分享
题解分享简介
扑克序列(结果填空) - 题解
```
#include <bits/stdc++.h>
using namespace std;
int a[] = {1, 1, 2, 2, 3, 3, 4, 4};
int out[8];
bool ist[8], done;
bool check() {
bool ist_[5];
memset(ist_, false, sizeof ist_);
for (int i = 0; i < 8; i ++)
if (!ist_[1] && out[i] == 1) {
for (int j = i + 1; j < 8; j ++) {
if (out[j] == 1) {
if (j - i - 1 != 1) return false;
ist[1] = true;
break;
}
}
if (!ist_[2] && out[i] == 2)
for (int j = i + 1; j < 8; j ++) {
if (out[j] == 2) {
if (j - i - 1 != 2) return false;
ist[2] = true;
break;
}
}
if (!ist_[3] && out[i] == 3)
for (int j = i + 1; j < 8; j ++) {
if (out[j] == 3) {
if (j - i - 1 != 3) return false;
ist[3] = true;
break;
}
}
if (!ist_[4] && out[i] == 4)
for (int j = i + 1; j < 8; j ++) {
if (out[j] == 4) {
if (j - i - 1 != 4) return false;
ist[4] = true;
break;
}
}
}
return true;
}
void dfs(int u) {
if (done) return;
if (u == 8) {
if (check()) {
for (int i = 0; i < 8; i ++) {
if (out[i] == 1) cout << 'A';
else cout << out[i];
}
puts("");
done = true;
}
return;
}
for (int i = 0; i < 8; i ++) {
if (!ist[i]) {
ist[i] = true;
out[u] = a[i];
dfs(u + 1);
ist[i] = false;
}
}
}
int main(void) {
dfs(0);
return 0;
}
```
查看全文
0
0
1
3
扑克序列(结果填空) - 题解
```
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
//
int a[2];
int b[2];
int c[2];
int d[2];
int ans;
bool check(string s)
{
int ia=0,ib=0,ic=0,id=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='1')a[ia++]=i;
if(s[i]=='2')b[ib++]=i;
if(s[i]=='3')c[ic++]=i;
if(s[i]=='4')d[id++]=i;
}
int cnta=0;
for(int i=a[0];i<=a[1];i++)cnta++;
if(cnta-2!=1)return false;
int cntb=0;
for(int i=b[0];i<=b[1];i++)cntb++;
if(cntb-2!=2)return false;
int cntc=0;
for(int i=c[0];i<=c[1];i++)cntc++;
if(cntc-2!=3)return false;
int cntd=0;
for(int i=d[0];i<=d[1];i++)cntd++;
if(cntd-2!=4)return false;
return true;
}
int arr[8]={1,1,2,2,3,3,4,4};
int main()
{
do{
string s="";
for(int i=0;i<8;i++)s+=arr[i]+'0';
if(check(s))
{
cout<<s<<endl;
return 0;
}
}while(next_permutation(arr,arr+8));
return 0;
}
//1--A --->2342A3A4
```
查看全文
0
0
1
0



