Loj#6434「PKUSC2018」主斗地(搜索)
题面
题解
细节比较多的搜索题。
首先现将牌型暴力枚举出来,大概是$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」主斗地(搜索)的更多相关文章
- 【LOJ】#6434. 「PKUSC2018」主斗地
题解 什么,我这题竟然快到了LOJ rk1???? 搜起来有点麻烦,不过感觉还是比斗地主好下手(至今没敢写斗地主 首先是暴力搜牌型,最多\(3^{16}\)(什么判解还要复杂度怂成一团)的样子?? 然 ...
- 「PKUSC2018」主斗地(暴搜)
这道斗地主比 \(PKUWC\) 那道可做多了... 我们用 \(NOIP\) 那道斗地主的思路:暴搜出三代和四代,贪心出散牌. 还有jry为什么要出xx网友而不出他的另一个老婆 我们发现两个人的每回 ...
- LOJ #6436. 「PKUSC2018」神仙的游戏(字符串+NTT)
题面 LOJ #6436. 「PKUSC2018」神仙的游戏 题解 参考 yyb 的口中的长郡最强选手 租酥雨大佬的博客 ... 一开始以为 通配符匹配 就是类似于 BZOJ 4259: 残缺的字符串 ...
- LOJ #6435. 「PKUSC2018」星际穿越(倍增)
题面 LOJ#6435. 「PKUSC2018」星际穿越 题解 参考了 这位大佬的博客 这道题好恶心啊qwq~~ 首先一定要认真阅读题目 !! 注意 \(l_i<r_i<x_i\) 这个条 ...
- LOJ #6432. 「PKUSC2018」真实排名(组合数)
题面 LOJ #6432. 「PKUSC2018」真实排名 注意排名的定义 , 分数不小于他的选手数量 !!! 题解 有点坑的细节题 ... 思路很简单 , 把每个数分两种情况讨论一下了 . 假设它为 ...
- Loj#6433「PKUSC2018」最大前缀和(状态压缩DP)
题面 Loj 题解 先转化题意,其实这题在乘了\(n!\)以后就变成了全排列中的最大前缀和的和(有点拗口).\(n\leq20\),考虑状压\(DP\) 考虑一个最大前缀和\(\sum\limits_ ...
- Loj#6432「PKUSC2018」真实排名(二分查找+组合数)
题面 Loj 题解 普通的暴力是直接枚举改或者不改,最后在判断最后对哪些点有贡献. 而这种方法是很难优化的.所以考虑在排序之后线性处理.首先先假设没有重复的元素 struct Node { int p ...
- Loj 6433. 「PKUSC2018」最大前缀和 (状压dp)
题面 Loj 题解 感觉挺难的啊- 状压\(dp\) 首先,有一个性质 对于一个序列的最大前缀和\(\sum_{i=1}^{p} A[i]\) 显然对于每个\(\sum_{i=p+1}^{x}A[i] ...
- Loj 6432. 「PKUSC2018」真实排名 (组合数)
题面 Loj 题解 枚举每一个点 分两种情况 翻倍or不翻倍 \(1.\)如果这个点\(i\)翻倍, 要保持排名不变,哪些必须翻倍,哪些可以翻倍? 必须翻倍: \(a[i] \leq a[x] < ...
随机推荐
- 51Nod 1004 n^n末尾数字 | 快速幂
#include "bits/stdc++.h" using namespace std; #define LL long long #define INF 0x3f3f3f3f3 ...
- SourceTree for mac 注册过程(v2.7.6a)
背景 为啥要自己注册呢,往上一堆一堆的老版本许可证偏不用,就愿意定制自己的账号style. 搞了半天,还是觉得pycharm自带的git工具就挺好用了,闲的没事记录一下. 要点 百度搜索的地址可以进入 ...
- 【BZOJ3453】XLkxc [拉格朗日插值法]
XLkxc Time Limit: 20 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 给定 k,a,n,d,p f(i ...
- bzoj 1731: [Usaco2005 dec]Layout 排队布局 ——差分约束
Description 当排队等候喂食时,奶牛喜欢和它们的朋友站得靠近些.FJ有N(2<=N<=1000)头奶牛,编号从1到N,沿一条直线站着等候喂食.奶牛排在队伍中的顺序和它们的编号是相 ...
- Linux 命令行生成密码的 10 种方式
内容来自: 10 Ways to Generate a Random Password from the Linux Command Line Linux 好玩的事儿是达成一件事情可以用上百种方式. ...
- 总有你要的编程书单(GitHub )
目录 IDE IntelliJ IDEA 简体中文专题教程 MySQL 21分钟MySQL入门教程 MySQL索引背后的数据结构及算法原理 NoSQL Disque 使用教程 Neo4j .rb 中文 ...
- hdu 2545 树上战争(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2545 树上战争 Time Limit: 10000/4000 MS (Java/Others) ...
- printk %pF %pS含义【转】
作者:啐楼链接:https://www.zhihu.com/question/37769890/answer/73532192来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
- sicily 1009. Mersenne Composite N
Description One of the world-wide cooperative computing tasks is the "Grand Internet Mersenne P ...
- C高级 框架开发中红黑树结构
引言 -- 红黑树历史 红黑树是数据结构学习中一道卡. 底层库容器中必不可少的算法. 历经各种实战运用,性能有保障. 同样红黑树不好理解, 就算理解了, 代码也不好写. 就算写了, 工程库也难构建. ...