题目传送门

昨天真题测试赛题目==

没想到一道纯到都不用剪枝的搜索会是noipT3难度。

不过因为我搜索弱啊所以打不出来==

LA:这不就是一道简单模拟题么

码完此题能增加对搜索的理解==

(闲话结束)

搜索,我们就是要遍历每一个可能的状态,来寻取最优解。每次我们尝试取到一个状态,然后递归回溯,之后恢复原来的状态。

具体的搜索过程,我们可以贪心地每次先打出耗费牌数更多的手牌,最后对特殊的小王大王情况 和单牌对牌进行处理。

 #include<algorithm>
#include<cstdio>
#include<cstring> using namespace std; int T,n,no,x,ans=;
int tong[]; void dfs(int now)
{
int cnt=;
for(int i=;i<=;i++)
{// shunzi single
if(tong[i]) cnt++;
else cnt=;
if(cnt>=)
{
tong[i]--,tong[i-]--,tong[i-]--,tong[i-]--;
int k=i-cnt+;
for(int j=i-;j>=k;j--)
tong[j]--,dfs(now+);
for(int j=k;j<=i;j++)
tong[j]++;
}
}
cnt=;
for(int i=;i<=;i++)
{// shunzi double
if(tong[i]>=) cnt++;
else cnt=;
if(cnt>=)
{
tong[i]-=,tong[i-]-=;
int k=i-cnt+;
for(int j=i-;j>=k;j--)
tong[j]-=,dfs(now+);
for(int j=k;j<=i;j++)
tong[j]+=;
}
}
cnt=;
for(int i=;i<=;i++)
{// shunzi third
if(tong[i]>=) cnt++;
else cnt=;
if(cnt>=)
{
tong[i]-=;
int k=i-cnt+;
for(int j=i-;j>=k;j--)
tong[j]-=,dfs(now+);
for(int j=k;j<=i;j++)
tong[j]+=;
}
}
for(int i=;i<=;i++)
{// four with 2
if(tong[i]>=)
{
tong[i]-=;
for(int j=;j<=;j++)
if(tong[j])
{//2 single
tong[j]--;
for(int k=;k<=;k++)
if(tong[k])
{
tong[k]--;
dfs(now+);
tong[k]++;
}
tong[j]++;
}
for(int j=;j<=;j++)
if(tong[j]>=)
{//2 double
tong[j]-=;
for(int k=;k<=;k++)
if(tong[k]>=)
{
tong[k]-=;
dfs(now+);
tong[k]+=;
}
tong[j]+=;
}
dfs(now+);
//three card
tong[i]+=;
}
}
for(int i=;i<=;i++)
{
if(tong[i]>=)
{
tong[i]-=;
for(int j=;j<=;j++)
if(tong[j])
{//three with 1
tong[j]--;
dfs(now+);
tong[j]++;
}
for(int j=;j<=;j++)
if(tong[j]>=)
{//three with 2
tong[j]-=;
dfs(now+);
tong[j]+=;
}
dfs(now+);// 3 single
tong[i]+=;
}
}
if(tong[]==) now++;
else if(tong[]==) now++;
for(int i=;i<=;i++) if(tong[i]) now+=tong[i]>>;
for(int i=;i<=;i++) if(tong[i]) now+=tong[i]&;
ans=min(ans,now);
} int main()
{
scanf("%d%d",&T,&n);
while(T--)
{
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&no);
if(x==) x=;
else if(x==) x=;
else if(x==) x=;
tong[x]++;
}
dfs();
printf("%d\n",ans);
ans=;
memset(tong,,sizeof(tong));
}
return ;
}

无注释版

 #include<algorithm>
#include<cstdio>
#include<cstring> using namespace std; int T,n,no,x,ans=;
int tong[]; void dfs(int now)
{
int cnt=;
for(int i=;i<=;i++)
{// shunzi single
if(tong[i]) cnt++;
else cnt=;
if(cnt>=)
{
tong[i]--,tong[i-]--,tong[i-]--,tong[i-]--;
int k=i-cnt+;// 顺子牌还要枚举找到起点
for(int j=i-;j>=k;j--)
tong[j]--,dfs(now+);
for(int j=k;j<=i;j++)
tong[j]++;
}
}
cnt=;
for(int i=;i<=;i++)
{// shunzi double
if(tong[i]>=) cnt++;
else cnt=;
if(cnt>=)
{
tong[i]-=,tong[i-]-=;
int k=i-cnt+;
for(int j=i-;j>=k;j--)
tong[j]-=,dfs(now+);
for(int j=k;j<=i;j++)
tong[j]+=;
}
}
cnt=;
for(int i=;i<=;i++)
{// shunzi third
if(tong[i]>=) cnt++;
else cnt=;
if(cnt>=)
{
tong[i]-=;
int k=i-cnt+;
for(int j=i-;j>=k;j--)
tong[j]-=,dfs(now+);
for(int j=k;j<=i;j++)
tong[j]+=;
}
}
for(int i=;i<=;i++)
{// four with 2
if(tong[i]>=)
{
tong[i]-=;
for(int j=;j<=;j++)
if(tong[j])
{//2 single
tong[j]--;
for(int k=;k<=;k++)
if(tong[k])
{
tong[k]--;
dfs(now+);
tong[k]++;
}
tong[j]++;//状态的恢复都是对称的
}
for(int j=;j<=;j++)
if(tong[j]>=)
{//2 double
tong[j]-=;
for(int k=;k<=;k++)
if(tong[k]>=)
{
tong[k]-=;
dfs(now+);
tong[k]+=;
}
tong[j]+=;
}
dfs(now+);
//three card
tong[i]+=;
}
}
for(int i=;i<=;i++)
{
if(tong[i]>=)
{
tong[i]-=;
for(int j=;j<=;j++)
if(tong[j])
{//three with 1
tong[j]--;
dfs(now+);
tong[j]++;
}
for(int j=;j<=;j++)
if(tong[j]>=)
{//three with 2
tong[j]-=;
dfs(now+);
tong[j]+=;
}
dfs(now+);// 3 single
tong[i]+=;
}
}
if(tong[]==) now++;
else if(tong[]==) now++;
for(int i=;i<=;i++) if(tong[i]) now+=tong[i]>>;//出对子牌
for(int i=;i<=;i++) if(tong[i]) now+=tong[i]&;//出单张牌 两者用位运算简化
ans=min(ans,now);//更新答案
} int main()
{
scanf("%d%d",&T,&n);
while(T--)
{
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&no);
if(x==) x=;
else if(x==) x=;
else if(x==) x=;
tong[x]++;
}
dfs();//现在已经出了0张牌
printf("%d\n",ans);
ans=;
memset(tong,,sizeof(tong));
}
return ;
}

有注释版

NOIp 2015 Day1T3斗地主【搜索】的更多相关文章

  1. 【UOJ #147】【NOIP 2015】斗地主

    http://uoj.ac/problem/147 搜索时先枚举三顺子,双顺子和单顺子,然后贪心带牌和成三成双成单出. #include<cstdio> #include<cstri ...

  2. 【NOIP 2015】斗地主

    题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的 A 到 K 加上大小王的共 54 张牌来进行的扑克牌游戏.在斗地主中,牌的大小关 系根据牌的数码表示如下: 3 ...

  3. Luogu 2668 NOIP 2015 斗地主(搜索,动态规划)

    Luogu 2668 NOIP 2015 斗地主(搜索,动态规划) Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来 ...

  4. 4632 NOIP[2015] 运输计划

    4632 NOIP[2015] 运输计划  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master 题解       题目描述 Description 公元 2044 ...

  5. [NOIP 2015]运输计划-[树上差分+二分答案]-解题报告

    [NOIP 2015]运输计划 题面: A[NOIP2015 Day2]运输计划 时间限制 : 20000 MS 空间限制 : 262144 KB 问题描述 公元 2044 年,人类进入了宇宙纪元. ...

  6. Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分)

    Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分) Description L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之 ...

  7. Luogu 1979 NOIP 2013 华容道(搜索,最短路径)

    Luogu 1979 NOIP 2013 华容道(搜索,最短路径) Description 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面 ...

  8. [普及]NOIP 2015 推销员 贪心

    NOIP 2015 推销员 题意: 有一个喜欢疲劳的推销员,告诉你在一个单口胡同(数轴)中的n户家庭的位置,和向他们推销可以获得的疲劳度.分别输出向(1,2,3,4...n)户人家推销可以得到的最大疲 ...

  9. cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分

    2109. [NOIP 2015] 运输计划 ★★★☆   输入文件:transport.in   输出文件:transport.out   简单对比时间限制:3 s   内存限制:256 MB [题 ...

随机推荐

  1. vs2010配置VL_FEAT库

    VL_FEAT库是计算机视觉中的一个开源库,支持C/C++,Matlab,可以在http://www.vlfeat.org/下载. 本文主要讲一下VS2010中如何配置vl_feat库(算是对原文的一 ...

  2. FIR300M刷openwrt

    淘宝看到一款FIR300M路由器,当时只要19.9元.图便宜就买了. Hardware Architecture: MIPS Vendor: MediaTek (Ralink) Bootloader: ...

  3. php浏览次数累加代码

    <?php $count=0; if(file_exists("count.txt")) //判断是否存在count.txt文件 { $count=file_get_cont ...

  4. C/C++用状态转移表联合函数指针数组实现状态机FSM

    状态机在project中使用很的频繁,有例如以下常见的三种实现方法: 1. switch-case 实现.适合简单的状态机. 2. 二维状态表state-event实现.逻辑清晰.可是矩阵通常比較稀疏 ...

  5. 关于chroot

    1 chroot做了什么 chroot只是修改了所有的path resolution过程,也就是说,chroot之后,所有的命令和库的根目录都是chroot到的目录. 2 chroot使用的条件 目标 ...

  6. 命令行唤起xcode模拟器

    1.IOS模拟器列表获取命令 xcrun instruments -s 2.IOS启动模拟器命令 xcrun instruments -w "iPhone 8 (12.1)"

  7. Your Firefox profile cannot be loaded. It may be missing or inaccessible

    ubuntu下出现打开frefox出现Your Firefox profile cannot be loaded. It may be missing or inaccessible 1:用命令行输入 ...

  8. linux内存操作--ioremap和mmap

    最近在做视频输出相关的东西,对于预留给framebuffer的内存使用不是很清楚,现在找到一些资料整理一下,以备使用.if (想看使用方法)  goto   使用方法: 对于一个系统来讲,会有很多的外 ...

  9. Adobe 官方公布的 RTMP 规范

    原文:  http://blog.csdn.net/defonds/article/details/17534903 RTMP 规范中文版 PDF 下载地址 译序:本文是为截至发稿时止最新 Adobe ...

  10. Android 代码设置RelativeLayout元素居中

    RelativeLayout relativeLayout= new RelativeLayout(this); RelativeLayout.LayoutParams rlp=new Relativ ...