题面

Loj

题解

细节比较多的搜索题。

首先现将牌型暴力枚举出来,大概是$3^{16}$吧。

然后再看能打什么,简化后无非就三种决策:单牌,$3+x$和$4+x$。

枚举网友打了几张$3$和$4$,然后再枚举吉老师($\mathbf {orz}$)打了几张$3$和$4$。

接着枚举$3$搭配了几个$2$,然后贪心地从大到小去除吉老师手中大小为$2$的对子,从小到大去除网友手中大小为$2$的对子。之后就是检查单牌是否合法了。

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll; template<typename T>
void read(T &x) {
int flag = 1; x = 0; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
} const int _ = 20;
char s[_];
int ans, cnt[_], a[_], orz[_];
int wy[_], jtkl[_], thr[_], fou[_], W[_], J[_], P[_]; int code (char c){
switch(c) {
case 'T': return 7;
case 'J': return 8;
case 'Q': return 9;
case 'K': return 10;
case 'A': return 11;
case '2': return 12;
case 'w': return 13;
case 'W': return 14;
default: return c - '4' + 1;
}
} bool check(int f, int t) {
for(int i = 0; i <= t; ++i) {
memcpy(W, wy, sizeof wy), memcpy(J, jtkl, sizeof jtkl);
if(2 * i + t - i + f * 2 + f * 4 + t * 3 > 17) break;
int cnt = 0;
for(int j = 1; j <= 14; ++j) {
if(W[j] >= 2 && cnt < i) W[j] -= 2, ++cnt;
if(W[j] >= 2 && cnt < i) W[j] -= 2, ++cnt;
if(cnt == i) break;
}
if(cnt < i) break; cnt = 0;
for(int j = 14; j >= 1; --j) {
if(J[j] >= 2 && cnt < i) J[j] -= 2, ++cnt;
if(J[j] >= 2 && cnt < i) J[j] -= 2, ++cnt;
if(cnt == i) break;
}
if(cnt < i) break;
memset(P, 0, sizeof P);
cnt = 2 * f + t - i;
for(int j = 14; j >= 1; --j) {
int t = min(cnt, J[j]);
J[j] -= t, cnt -= t;
if(!cnt) break;
}
if(cnt) continue;
cnt = 2 * f + t - i;
for(int j = 1; j <= 14; ++j) {
int t = min(cnt, W[j]);
W[j] -= t, cnt -= t;
if(!cnt) break;
}
if(J[14]) continue;
for(int j = 1; j <= 14; ++j)
P[j] += W[j], P[j + 1] -= J[j];
cnt = 0;
for(int j = 1; j <= 14; ++j) {
cnt += P[j];
if(cnt > 0) break;
}
if(!cnt) return true;
} return false;
} bool check_jtkl(int now, int four, int three, int f, int t, int q1, int q2) {
if(four == f && three == t) return check(f, t);
if(now >= 12) return false;
q1 += thr[now], q2 += fou[now];
if(q1 > 0 || q2 > 0) return false;
if(jtkl[now] >= 3) {
jtkl[now] -= 3;
if(check_jtkl(now + 1, four, three, f, t + 1, q1 - 1, q2)) return true;
jtkl[now] += 3;
}
if(jtkl[now] >= 4) {
jtkl[now] -= 4;
if(check_jtkl(now + 1, four, three, f + 1, t, q1, q2 - 1)) return true;
jtkl[now] += 4;
}
return check_jtkl(now + 1, four, three, f, t, q1, q2);
} bool check_wy (int now, int four, int three) {
if(four * 6 + three * 4 > 17) return false;
if(now > 12) return check_jtkl(1, four, three, 0, 0, 0, 0);
if(wy[now] >= 3) {
wy[now] -= 3, ++thr[now];
if(check_wy(now + 1, four, three + 1)) return true;
wy[now] += 3, --thr[now];
}
if(wy[now] >= 4) {
wy[now] -= 4, ++fou[now];
if(check_wy(now + 1, four + 1, three)) return true;
wy[now] += 4, --fou[now];
}
return check_wy(now + 1, four, three);
} void dfs(int now, int rest) {
if(!rest) {
memset(thr, 0, sizeof thr);
memset(fou, 0, sizeof fou);
memcpy(wy, a, sizeof a);
memcpy(jtkl, orz, sizeof orz);
if(check_wy(2, 0, 0)) ++ans;
return ;
}
if(now > 14) return ;
for(int i = 0; i <= cnt[now]; ++i) {
if(i > rest) break;
orz[now] = i, dfs(now + 1, rest - i), orz[now] = 0;
}
} int main () {
while(scanf("%s", s + 1) != EOF) {
memset(a, 0, sizeof a);
for(int i = 1; i <= 12; ++i) cnt[i] = 4;
cnt[13] = cnt[14] = 1, ans = 0;
for(int i = 1; i <= 17; ++i)
++a[code(s[i])], --cnt[code(s[i])];
dfs(1, 17), printf("%d\n", ans);
}
return 0;
}

Loj#6434「PKUSC2018」主斗地(搜索)的更多相关文章

  1. 【LOJ】#6434. 「PKUSC2018」主斗地

    题解 什么,我这题竟然快到了LOJ rk1???? 搜起来有点麻烦,不过感觉还是比斗地主好下手(至今没敢写斗地主 首先是暴力搜牌型,最多\(3^{16}\)(什么判解还要复杂度怂成一团)的样子?? 然 ...

  2. 「PKUSC2018」主斗地(暴搜)

    这道斗地主比 \(PKUWC\) 那道可做多了... 我们用 \(NOIP\) 那道斗地主的思路:暴搜出三代和四代,贪心出散牌. 还有jry为什么要出xx网友而不出他的另一个老婆 我们发现两个人的每回 ...

  3. LOJ #6436. 「PKUSC2018」神仙的游戏(字符串+NTT)

    题面 LOJ #6436. 「PKUSC2018」神仙的游戏 题解 参考 yyb 的口中的长郡最强选手 租酥雨大佬的博客 ... 一开始以为 通配符匹配 就是类似于 BZOJ 4259: 残缺的字符串 ...

  4. LOJ #6435. 「PKUSC2018」星际穿越(倍增)

    题面 LOJ#6435. 「PKUSC2018」星际穿越 题解 参考了 这位大佬的博客 这道题好恶心啊qwq~~ 首先一定要认真阅读题目 !! 注意 \(l_i<r_i<x_i\) 这个条 ...

  5. LOJ #6432. 「PKUSC2018」真实排名(组合数)

    题面 LOJ #6432. 「PKUSC2018」真实排名 注意排名的定义 , 分数不小于他的选手数量 !!! 题解 有点坑的细节题 ... 思路很简单 , 把每个数分两种情况讨论一下了 . 假设它为 ...

  6. Loj#6433「PKUSC2018」最大前缀和(状态压缩DP)

    题面 Loj 题解 先转化题意,其实这题在乘了\(n!\)以后就变成了全排列中的最大前缀和的和(有点拗口).\(n\leq20\),考虑状压\(DP\) 考虑一个最大前缀和\(\sum\limits_ ...

  7. Loj#6432「PKUSC2018」真实排名(二分查找+组合数)

    题面 Loj 题解 普通的暴力是直接枚举改或者不改,最后在判断最后对哪些点有贡献. 而这种方法是很难优化的.所以考虑在排序之后线性处理.首先先假设没有重复的元素 struct Node { int p ...

  8. Loj 6433. 「PKUSC2018」最大前缀和 (状压dp)

    题面 Loj 题解 感觉挺难的啊- 状压\(dp\) 首先,有一个性质 对于一个序列的最大前缀和\(\sum_{i=1}^{p} A[i]\) 显然对于每个\(\sum_{i=p+1}^{x}A[i] ...

  9. Loj 6432. 「PKUSC2018」真实排名 (组合数)

    题面 Loj 题解 枚举每一个点 分两种情况 翻倍or不翻倍 \(1.\)如果这个点\(i\)翻倍, 要保持排名不变,哪些必须翻倍,哪些可以翻倍? 必须翻倍: \(a[i] \leq a[x] < ...

随机推荐

  1. iOS排序

    NSArray *originalArray = @[@,@,@,@,@]; //block比较方法,数组中可以是NSInteger,NSString(需要转换) NSComparator finde ...

  2. Ant复制文件

    <?xml version="1.0" encoding="UTF-8"?> <project name ="test" ...

  3. 【BZOJ1221】【HNOI2001】软件开发 [费用流]

    软件开发 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 某软件公司正在规划一项n天的软件开 ...

  4. R、Python、Scala和Java,到底该使用哪一种大数据编程语言?

    有一个大数据项目,你知道问题领域(problem domain),也知道使用什么基础设施,甚至可能已决定使用哪种框架来处理所有这些数据,但是有一个决定迟迟未能做出:我该选择哪种语言?(或者可能更有针对 ...

  5. Frogs' Neighborhood(POJ1659+Havel-Hakimi定理)

    题目链接:http://poj.org/problem?id=1659 题目: 题意:根据他给你的每个点的度数构造一张无向图. 思路:自己WA了几发(好菜啊……)后看到discuss才知道这个要用Ha ...

  6. HDU 1422 重温世界杯 (dp)

    题目链接 Problem Description 世界杯结束了,意大利人连本带利的收回了法国人6年前欠他们的债,捧起了大力神杯,成就了4星意大利. 世界杯虽然结束了,但是这界世界杯给我们还是留下许多值 ...

  7. python dlib 面部轮廓实时检测

    1.dlib 实现动态人脸检测及面部轮廓检测 模型下载连接 : http://dlib.net/files/ # coding:utf-8 import cv2 import os import dl ...

  8. 八大疯狂的HTML5 Canvas及WebGL动画效果——8 CRAZY ANIMATIONS WITH WEBGL AND HTML5 CANVAS【收藏】

    HTML5, WebGL and Javascript have changed the way animation used to be. Past few years, we can only a ...

  9. Perl6 Bailador框架(3):路径匹配

    use v6; use Bailador; =begin pod 注意的是, 当/:one设置时 虽然你有/admin或/about, 但这个/:one不会跟现有的匹配 只跟没有的匹配: 也就是说, ...

  10. perl中的lock

    #!/usr/bin/env perl -w use strict; use threads; use threads::shared; ; print "count的起始值为:$count ...