题目传送门

昨天真题测试赛题目==

没想到一道纯到都不用剪枝的搜索会是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. Jsp在Web.xml中的配置

    以下列出web.xml经常使用的标签元素及这些标签元素的功能: 1.指定欢迎页面.比如: <welcome-file-list> <welcome-file-list> < ...

  2. 【DataStructure】Description and Introduction of Tree

    [Description] At ree is a nonlinear data structure that models a hierarchical organization. The char ...

  3. 我遇到的错误curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused

    今天我用curl命令,无论如何都是出现: curl: (7) Failed to connect to 127.0.0.1 port 1086: Connection refused 找了很久,不知道 ...

  4. Hadoop提供的reduce函数中Iterable 接口只能遍历一次的问题

    今天在写MapReduce中的reduce函数时,碰到个问题,特此记录一下: void reduce(key, Iterable<*>values,...) { for(* v:value ...

  5. if return 和 if else

    最近看Node.js实战中,有一段代码是优化之前使用if else,优化之后是使用if return,我不知道if return是不是效率比if else高. 优化前: if(err){ handle ...

  6. Java 快速失败( fail-fast ) 安全失败( fail-safe )

    原文:http://www.cnblogs.com/ygj0930/p/6543350.html 快速失败( fail-fast ):当你在迭代一个集合的时候,如果有另一个线程正在修改你正在访问的那个 ...

  7. (linux)schedule_delayed_work()

      原文地址:schedule_delayed_work()用法作者:Valley   第一篇 工作队列       在Linux内核中,对下半部(或者说推后执行的工作)的处理方式有好几种,包括BH( ...

  8. 概率dp集合

    bzoj1076 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后 ...

  9. Linux内核中工作队列的使用work_struct,delayed_work【转】

    本文转载自:http://blog.csdn.net/zahuopuboss/article/details/43268983 初始化工作队列 调度工作队列 取消工作队列 #include <l ...

  10. import data from excel to sql server

    https://www.c-sharpcorner.com/article/how-to-import-excel-data-in-sql-server-2014/ 需要注意的是,第一次是选择sour ...