LOJ2422 NOIP2015 斗地主


LINK


题目大意很简单,就是问你斗地主的一分手牌最少多少次出完


然后我们发现对于一种手牌状态,不考虑顺子的情况是可以贪心做掉的

然后我们直接枚举一下顺子出牌情况就可以了


LOJ上的数据随便写点基本贪心就行了

如果想过UOJ上的加强版的话还是把中间那一部分毒瘤的特判更优情况加上吧


当然也有个Smallfat大神用DP做掉的

我感觉DP更严谨一些,但是毕竟贪心好写嘛


 #include<bits/stdc++.h>
using namespace std;
#define N 20
int n,ans,is;
int col[N],cnt[N],tmp[N];
int cal(){
for(int i=;i<=;i++)tmp[i]=cnt[i];
int res=;
while(tmp[]&&tmp[]>=)res++,tmp[]--,tmp[]-=;
while(tmp[]&&tmp[]>=)res++,tmp[]--,tmp[]-=;
//
while(tmp[]&&!tmp[]&&tmp[]>=&&tmp[]) res+=,tmp[]--,tmp[]-=,tmp[]--;
while(!tmp[]&&tmp[]&&tmp[]>=&&!tmp[]) res+=,tmp[]--,tmp[]-=;
while(tmp[]&&tmp[]&&tmp[]&&tmp[]>=) res+=,tmp[]--,tmp[]--,tmp[]--,tmp[]-=;
while(tmp[]&&tmp[]&&!tmp[]&&tmp[]>=) res+=,tmp[]--,tmp[]--,tmp[]-=;
while(!tmp[]&&!tmp[]&&tmp[]>=&&tmp[]>=)res+=,tmp[]-=,tmp[]-=;
while(!tmp[]&&!tmp[]&&tmp[]>=&&tmp[]) res+=,tmp[]-=,tmp[]--;
//
while(tmp[]&&tmp[])res++,tmp[]--,tmp[]--;
while(tmp[]>=)res++,tmp[]-=;
while(tmp[]&&tmp[])res++,tmp[]--,tmp[]--;
while(tmp[]&&tmp[])res++,tmp[]--,tmp[]--;
if(is&&tmp[]>=)tmp[]-=,res++;
return res+tmp[]+tmp[]+tmp[]+tmp[];
}
bool check(int l,int r,int num){
for(int i=l;i<=r;i++)if(col[i]<num)return ;
return ;
}
void modify(int l,int r,int num){
for(int i=l;i<=r;i++){
cnt[col[i]]--;
col[i]+=num;
cnt[col[i]]++;
}
}
void dfs(int step){
if(step>=ans)return;
ans=min(ans,step+cal());
for(int l=;l<=;l++){
for(int len=;len+l-<=;len++){
int r=len+l-;
if(!check(l,r,))break;
modify(l,r,-);
dfs(step+);
modify(l,r,);
}
}
for(int l=;l<=;l++){
for(int len=;len+l-<=;len++){
int r=len+l-;
if(!check(l,r,))break;
modify(l,r,-);
dfs(step+);
modify(l,r,);
}
}
for(int l=;l<=;l++){
for(int len=;len+l-<=;len++){
int r=len+l-;
if(!check(l,r,))break;
modify(l,r,-);
dfs(step+);
modify(l,r,);
}
}
}
void solve(){
int op,x;ans=n;
for(int i=;i<=;i++)col[i]=,cnt[i]=;
for(int i=;i<=n;i++){
scanf("%d%d",&op,&x);
if(op>)op--;
else if(op)op=;
col[op]++;
}
for(int i=;i<=;i++)if(col[i])cnt[col[i]]++;
cnt[]+=col[];
is=(col[]==);
dfs();
printf("%d\n",ans);
}
int main(){
int T;scanf("%d%d",&T,&n);
while(T--)solve();
return ;
}

LOJ2422 NOIP2015 斗地主 【搜索+贪心】*的更多相关文章

  1. 【BZOJ4325】NOIP2015 斗地主 搜索+贪心

    这个东西考试的时候一眼以为状压就压炸了考试又了一下午.....最后我打出来发现后几个点10min都过不去,我大概算了一下,可能是吧.......最后一脸懵逼的我去怂了正解,我们发现只要确定了顺子就可以 ...

  2. NOIP2015斗地主[DFS 贪心]

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

  3. 【BZOJ4325】NOIP2015 斗地主 搜索+剪枝

    [BZOJ4325]NOIP2015 斗地主 Description 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗 ...

  4. 2018.11.01 bzoj4325: NOIP2015 斗地主(贪心+搜索)

    传送门 原来一直以为是一道大模拟. 没想到是一道搜索+最优性剪枝 如何搜最优呢? 我们考虑怎么最快出完. 大概是应该尽量出当前能出出去最多的吧. 于是我们选择优先出顺子. 这样做有什么好处呢? 我们会 ...

  5. 洛谷 2668&2540 斗地主——搜索+贪心+dp

    题目:https://www.luogu.org/problemnew/show/P2540 发现如果没有顺子,剩下的可以贪心.所以搜索顺子怎么出,然后贪心. 这样只能过不加强版.原因是贪心的时候难以 ...

  6. 洛谷 P2668 & P2540 [ noip 2015 ] 斗地主 —— 搜索+贪心

    题目:https://www.luogu.org/problemnew/show/P2668   https://www.luogu.org/problemnew/show/P2540 首先,如果没有 ...

  7. NOIP2015 斗地主(搜索+剪枝)

    4325: NOIP2015 斗地主 Time Limit: 30 Sec  Memory Limit: 1024 MBSubmit: 270  Solved: 192[Submit][Status] ...

  8. 2106. [NOIP2015] 斗地主

        2106. [NOIP2015] 斗地主 ★★★☆   输入文件:landlords.in   输出文件:landlords.out   简单对比 时间限制:2 s   内存限制:1025 M ...

  9. BZOJ 4325: NOIP2015 斗地主

    4325: NOIP2015 斗地主 Time Limit: 30 Sec  Memory Limit: 1024 MBSubmit: 684  Solved: 456[Submit][Status] ...

随机推荐

  1. js添加事件 attachEvent 和addEventListener的用法

    一般我们在JS中添加事件,是这样子的: obj.onclick = method 这种绑定事件的方式,兼容主流浏览器,但是如果一个元素上添加多次同一个事件呢??? obj.onclick = meth ...

  2. 可能是最好的 Rx 初学者教程

    译文:https://zhuanlan.zhihu.com/p/25552305 原文:https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

  3. 英语每日阅读---8、VOA慢速英语(翻译+字幕+讲解):脸肓症患者记不住别人的脸

    英语每日阅读---8.VOA慢速英语(翻译+字幕+讲解):脸肓症患者记不住别人的脸 一.总结 一句话总结: a.neural abnormalities are more widespread:Duc ...

  4. 《Think in Java》(十二)通过异常处理错误

    异常虽然简单,但是很有用!学完这一章还是发现 Java 异常还是有很多可学之处的,比如:异常说明,异常链等.

  5. js从数组中随机获取n个不重复的数据

    做云课堂的作业时遇到一要求,实现刷新页面时显示不同数据,(数组中20个据,页面加载10个).思路就是从0-19中随机生成10个不同的数,让数组取下标输出数据. 下面是在num的范围内生成n个不重复的数 ...

  6. bzoj2547

    题解: 二分+宽搜+KM 显然答案不能太大 然后二分一下 代码: #include<bits/stdc++.h> ,M=; using namespace std; ]={-,,,},dy ...

  7. ZOJ 1609 Equivalence(状压+dfs减枝)

    ZOJ Problem Set - 1609 Equivalence Time Limit: 5 Seconds      Memory Limit: 32768 KB When learning m ...

  8. TCP三次握手,四次挥手,状态变迁图

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  9. eclipse集群tomcat

    eclipse集群tomcat 1.  File -> new -> other 选择server. 2.  选择Apache下边对应的tomcat版本,配置tomcat名称即可.由于我本 ...

  10. d3.js(v5.7)力导向图(关系图谱)

    先上图,后面再一一解释: ok,为了方便理解,这里我就没有用之前封装的automatch函数来将数据和节点匹配了,如果你对enter(),exit()函数还不是很理解的话,请移步至我之前写的<n ...