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. 04_MySQL常见函数_单行函数

    #单行函数细分1.字符函数2.数学函数3.日期函数4.其他函数5.流程控制函数 #单行函数 - 字符函数#一.字符函数#1. length 获取参数的字节长度SELECT LENGTH('john') ...

  2. webjars-jquery的引用

    什么是WebJars WebJars以jar包的形式来使用前端的各种框架.组件,如jquery.bootstrap WebJars将客户端(浏览器)资源(JavaScript,Css等)打成jar包文 ...

  3. Mac 终端命令行报错 -bash: vi: command not found

    我遇到的问题与这个类似,但是我的问题也是用该博文作者方法进行中断才解决的,在此表示感谢. 前段时间在 Mac 下使用终端遇到了这个问题: appledeMacBook-Air:~ air$ vi .b ...

  4. angularjs控制器之间的数据共享与通信

    1.可以写一个service服务,从而达到数据和代码的共享; var app=angular.module('app',[]); app.service('ObjectService', [Objec ...

  5. Redis原理与实践总结

    Redis原理与实践总结 本文主要对Redis的设计和实现原理做了一个介绍很总结,有些东西我也介绍的不是很详细准确,尽量在自己的理解范围内把一些知识点和关键性技术做一个描述.如有错误,还望见谅,欢迎指 ...

  6. UVA-10917 Walk Through the Forest (dijkstra+DP)

    题目大意:n个点,m条边的无向图.一个人从起点到终点按照下面的走法:从A走向B当A到终点的最小距离比B到终点的最小距离大时.问从起点到终点有多少路径方案. 题目分析:先用dijkstra预处理出终点到 ...

  7. pyhon SyntaxError: Non-ASCII character '\xe8' in file xxx on line xx, but no encoding

    import math if __name__ == '__main__':    name1 = raw_input("请输入您的编号:")    print name1 完整的 ...

  8. Jdev 本地RUN页面时候,将异常直接显示出来,而不是乱码

    本地运行页面时,经常会遇到以下错误 oracle.jbo.JboException: JBO-29000: JBO-29000: JBO-26028: ???? MemberAttributesDis ...

  9. ASP.NET MVC添加Action就找不到

    这个诡异的bug困扰我好多回了,今天又碰到了,就把它记录下来吧. 不要随便改变web项目的编译路径 Output让它保持原样就好了...

  10. L159

    Waves are the children of the struggle between ocean and atmosphere, the ongoing signatures of infin ...