栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3669 Japanese Mahjong I

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3669 Japanese Mahjong I

#include <vector>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char str[15];int cnt[4][14];int ctoi(char c){ if(c == 'm') return 0; if(c == 'p') return 1; if(c == 's') return 2; if(c == 'z') return 3;}int itoc(int i){ if(i == 0) return 'm'; if(i == 1) return 'p'; if(i == 2) return 's'; if(i == 3) return 'z';}bool dfs(){ for(int i=0;i<4;i++){ for(int j=1;j<=(i==3?7:9);j++){ if(!cnt[i][j]) continue;  if(cnt[i][j]>= 3){ cnt[i][j] -= 3; if(dfs()){ cnt[i][j] += 3; return true; } cnt[i][j] += 3; } if(i != 3 && cnt[i][j] && cnt[i][j+1] && cnt[i][j+2]) { cnt[i][j]--;cnt[i][j+1]--;cnt[i][j+2]--; if(dfs()){ cnt[i][j]++;cnt[i][j+1]++;cnt[i][j+2]++; return true;  } cnt[i][j]++;cnt[i][j+1]++;cnt[i][j+2]++; } return false;  } } return true; }bool win(){ for(int i=0;i<4;i++){ for(int j=1;j<=(i==3?7:9);j++){ if(cnt[i][j] >= 2){ cnt[i][j] -= 2; if(dfs()){ cnt[i][j] += 2; return true; } cnt[i][j] += 2; } } } return false;}int main(){ while(~scanf("%s",str)) { memset(cnt,0,sizeof(cnt)); for(int i=0;str[i];i+=2){ cnt[ ctoi(str[i+1]) ][ str[i]-'0' ]++; } vector< pair<int,int> > ans; for(int i=0;i<4;i++){ for(int j=1;j<=(i==3?7:9);j++){ if(cnt[i][j] == 4) continue; cnt[i][j]++; if(win()) ans.push_back(make_pair(i,j)); cnt[i][j]--; } } printf("%d",(int)ans.size()); if((int)ans.size()){ putchar(' '); for(int i=0;i<(int)ans.size();i++) printf("%d%c",ans[i].second,itoc(ans[i].first)); } puts(""); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380626.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号