字节跳动ZJ20->雀魂启动
雀魂启动!
http://www.nowcoder.com/questionTerminal/448127caa21e462f9c9755589a8f2416
1. 这道题解法很有意思,忘记哪儿看到的了,希望有人告知出处
- 将所有出的次数用桶的存起来,
- i从每个数开始遍历尝试,期间嵌套j作为雀头尝试【原本自己思路没有好的方法实现,只能两重循环】
#include<bits/stdc++.h> using namespace std; int main(){ int number;//牌 int num;//听的牌 int hu=1; int result=0; int count[11]={0,0,0,0,0,0,0,0,0,0,0};//记录每个数的张数,count[0]不用 int temp[11]; for(int i=0;i<13;i++){ cin >> number; count[number]++; } for(num=1;num<10;num++){//依次插入10个数进行尝试 memcpy(temp, count, sizeof(count)); temp[num]++;//加上这张牌成为手牌 if(temp[num]>4)//多于4张是肯定不行的 continue; for(int j=1;j<10;j++){//j依次测试雀头 memcpy(temp, count, sizeof(count)); temp[num]++; if(temp[j]>=2){//只要有数目多于2,就有雀头 temp[j]=temp[j]-2;//将雀头消去 hu=1; for(int z=1;z<10;z++){//这趟用于测试顺子和壳子 if(temp[z]>=3){//只要数目大于等于3,那就是刻子 temp[z]=temp[z]-3; } if(temp[z]==2&&temp[z+1]>1&&temp[z+2]>1){//刻子已去,只剩顺子 temp[z]=temp[z]-2; temp[z+1]=temp[z+1]-2; temp[z+2]=temp[z+2]-2; } if(temp[z]==1&&temp[z+1]>0&&temp[z+2]>0){//刻子已去,只剩顺子 temp[z]--; temp[z+1]--; temp[z+2]--; } if(temp[z]){//一趟下来还有剩,说明胡不了 hu=0; break; } } if(hu){ result++; printf("%d ", num); } } } } if(!result) printf("%d",0); return 0; }