HDU 4930 Fighting the Landlords 模拟
时间:2014-08-07 23:04:35
收藏:0
阅读:356
_(:зゝ∠)_
4带2居然不是炸弹,,
#include <algorithm>
#include <cctype>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <climits>
#include <vector>
#include<iostream>
using namespace std;
#define N 18
#define inf 1000000
#define ll int
struct node{
int a[N];
int siz, kind;
void init(int s, int k){memset(a, 0, sizeof a); siz = s;kind = k;}
}x, y, z;
int fuck(char c){
if('3'<=c&&c<='9')return c-'0';
else if(c=='T') return 10;
else if(c=='J') return 11;
else if(c=='Q') return 12;
else if(c=='K') return 13;
else if(c=='A') return 14;
else if(c=='2') return 15;
else if(c=='X') return 16;
return 17;
}
void go(char *s, node &a){
memset(a.a, 0, sizeof a.a);
a.siz = strlen(s);
for(int i = 0; s[i]; i++)
a.a[fuck(s[i])] ++;
}
char s[N], t[N], tmp[N];
int top, n, m;
void hav_tmp(int x){
top = 0;
int i = 0;
while(x){
if(x&1) tmp[top++] = s[i];
i++;
x>>=1;
}
tmp[top] = 0;
}
bool ok(){
int kind = x.kind;
if( kind == 0 )return false;
if(x.siz == n)return true;
if(y.a[16] && y.a[17]) return false;
if(kind != 9 && kind != 6) {
for(int i = 15; i >= 3; i--)
if(y.a[i] == 4)return false;
}
if(kind <= 3 || kind == 9) {
int yi;
for(int i = 17; i >= 3; i--)if(x.a[i]){yi = i;break;}
for(int i = 17; i > yi; i--)
if(y.a[i] >= kind || y.a[i] == 4)return false;
return true;
}
if(y.siz < kind)return false;
if(kind == 6) {
int si ;
for(int i = 15 ; i>=3; i--)if(x.a[i]==4)si = i;
for(int i = 15; i > si; i--)if(y.a[i]==4)return false;
return true;
}
int san;
for(int i = 15; i >= 3; i--)if(x.a[i]==3)san = i;
for(int i = 15; i > san; i--)if(y.a[i]>=3)
return false;
return true;
}
bool work(){
for(int i = 17; i >= 3; i--)if(z.a[i])
{
x.init(1,1); x.a[i]++;
if(ok())return true;
break;
}
for(int i = 17; i >= 3; i--)if(z.a[i]==2){
x.init(2,2); x.a[i]=2;
if(ok())return true;
break;
}
for(int i = 17; i >= 3; i--)if(z.a[i]==3){
x.init(3,3); x.a[i]=3;
if(ok())return true;
if(z.siz >= 4){
x.init(4,4);
x.a[i]=3;
x.a[i+1] = 1;
if(ok())return true;
}
if(z.siz >= 5){
x.init(5,5);
x.a[i]=3;
x.a[i+1] = 2;
if(ok())return true;
}
break;
}
for(int i = 17; i >= 3; i--)if(z.a[i]==4){
x.init(4,9); x.a[i]=4;
if(ok())return true;
if(z.siz >= 6){
x.init(6, 6);
x.a[i]=4;
x.a[i+1] = 2;
if(ok())return true;
}
break;
}
return false;
}
int main(){
int T; cin>>T;
while(T--){
scanf("%s",s);
scanf("%s",t);
n = strlen(s); m = strlen(t);
go(t, y);
go(s, z);
if(z.a[16] && z.a[17]){puts("Yes");continue;}
work() ? puts("Yes"):puts("No");
}
return 0;
}
/*
99
33A
2
33A
22
33
22
5559T
9993
555
3333
55522
3333
555777
3333
35
7
39
7
XY
2222AAAA
Y
K
22
AA3333
222
AA3333
3333
XY
333342
XY
*/
评论(0)