【NOIP2015】斗地主
2017-07-04 15:56
375 查看
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #define RG register #define IL inline #define pi acos(-1.0) #define ll long long using namespace std; int gi() { char ch=getchar(); int x=0; while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') {x=10*x+ch-'0';ch=getchar();} return x; } int T,n,ans; int num[10],cnt[20]; int others() { int tot=0; memset(num,0,sizeof(num)); for(int i=1; i<=14; i++) num[cnt[i]]++; while(num[4] && num[2]>=2) tot++,num[4]--,num[2]-=2; while(num[4] && num[1]>=2) tot++,num[4]--,num[1]-=2; while(num[4] && num[2]>=1) tot++,num[4]--,num[2]--; while(num[3] && num[2]>=1) tot++,num[3]--,num[2]--; while(num[3] && num[1]>=1) tot++,num[3]--,num[1]--; return tot+num[1]+num[2]+num[3]+num[4]; } void dfs(int k) { if(k>=ans) return; ans=min(ans,others()+k);//在当前出牌阶段强行把牌打光的次数 for(int i=3; i<=13; i++) { if(cnt[i]>=3) { int j=i; while(cnt[j]>=3 && j<=14) j++; if(j-i>=2) { for(int l=i+1; l<j; l++) { for(int p=i; p<=l; p++) cnt[p]-=3; dfs(k+1); for(int p=i; p<=l; p++) cnt[p]+=3; } } } } for(int i=3; i<=12; i++) { if(cnt[i]>=2) { int j=i; while(cnt[j]>=2 && j<=14) j++; if(j-i>=3) { for(int l=i+2; l<j; l++) { for(int p=i; p<=l; p++) cnt[p]-=2; dfs(k+1); for(int p=i; p<=l; p++) cnt[p]+=2; } } } } for(int i=3; i<=10; i++) { if(cnt[i]>=1) { int j=i; while(cnt[j]>=1 && j<=14) j++; if(j-i>=5) { for(int l=i+4; l<j; l++) { for(int p=i; p<=l; p++) cnt[p]--; dfs(k+1); for(int p=i; p<=l; p++) cnt[p]++; } } } } } int main() { T=gi(),n=gi(); while(T--) { ans=1<<30; memset(cnt,0,sizeof(cnt)); for(int i=1; i<=n; i++) { int numb=gi(),col=gi(); if(numb==1) numb=14;//A变成14 if(numb==0) numb=1;//大小王变成1 cnt[numb]++; } dfs(0); printf("%d\n", ans); } return 0; } /* 多组数据重复使用的数组没有清零 三个for要分开写,要把三对的先打完,再二对...... 四张带一对也是可以的 注意搜顺子的时候不一定要把顺子全部打出去 因为可能把顺子直接打出去之后剩的都是单牌了 */
相关文章推荐
- 4325. 【NOIP2015提高组Day1】斗地主
- [NOIp 2015]斗地主
- BZOJ 4325: NOIP2015 斗地主
- 洛谷P2668 斗地主(NOIp2015)(BZOJ4325)
- [NOIP2015]斗地主 搜索+贪心
- 【NOIP2015】斗地主
- noip2015 day1 斗地主
- 【NOIP 2015】斗地主 贪心+迭代加深搜索
- UOJ 147 & 151 [NOIP2015]斗地主
- 【NOIP】提高组2015 斗地主
- NOIP2015 Day 1 T3 斗地主
- [NOIP2015] 斗地主 大爆搜
- 【bzoj4325】NOIP2015 斗地主(&“加强”版) 搜索
- [NOIp2015] 斗地主
- 斗地主 (NOIP2015 Day1 T3)
- [NOIP2015] 提高组 洛谷P2668 斗地主
- noip2015 斗地主
- [NOIP2015]斗地主
- UOJ147 [NOIP2015]斗地主 解题报告【搜索】【贪心】
- 【NOIP2015】Day1T3 斗地主