首页 > 其他分享 >2022 ICPC合肥 M Mahjong

2022 ICPC合肥 M Mahjong

时间:2022-11-21 00:22:25浏览次数:59  
标签:int 听牌 long ICPC vis Mahjong 2022 include

Mahjong

爆搜

先搜索出所有胡牌的情况,然后根据胡牌的情况,随便丢掉一张牌,则肯定是听牌状态

然后枚举所有的听牌状态,计算其听牌集合,存起来即可

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <map>
#include <array>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
map<ll, ll>mp, ans, tag;
int vis[10];

void solve()
{
    ll now = 0;
    for(int j=1; j<10; j++)
    {
        for(int k=0; k<vis[j]; k++)
        {
            now *= 10;
            now += j;
        }
    }
    if(tag[now]) return;
    tag[now] = 1;
    ll last = 0;
    for(int i=1; i<10; i++)
    {
        if(vis[i] == 4) continue;
        vis[i]++;
        ll tot = 0;
        for(int j=1; j<10; j++)
        {
            for(int k=0; k<vis[j]; k++)
            {
                tot *= 10;
                tot += j;
            }
        }
        if(mp.count(tot))
        {
            last *= 10;
            last += i;
        }
        vis[i]--;
    }
    ans[last] = now;
}

void dfs(int now, int cnt, int sum)
{
    if(vis[now] == 4) now++;
    if(cnt == 5)
    {
        if(sum != 14) return;
        ll tot = 0;
        for(int i=1; i<=9; i++)
        {
            for(int j=0; j<vis[i]; j++)
            {
                tot *= 10;
                tot += i;
            }
        }
        mp[tot] = 1;
        return;
    }
    if(now >= 10) return;

    if(vis[now] <= 2 && sum % 3 == 0)
    {
        vis[now] += 2;
        dfs(now, cnt + 1, sum + 2);
        vis[now] -= 2;
    }
    if(vis[now] <= 1)
    {
        vis[now] += 3;
        dfs(now, cnt + 1, sum + 3);
        vis[now] -= 3;
    }
    if(now <= 7 && vis[now] <= 3 && vis[now + 1] <= 3 && vis[now + 2] <= 3)
    {
        vis[now]++;
        vis[now + 1]++;
        vis[now + 2]++;
        dfs(now, cnt + 1, sum + 3);
        vis[now]--;
        vis[now + 1]--;
        vis[now + 2]--;
    }
    dfs(now + 1, cnt, sum);
}

int main()
{
    dfs(1, 0, 0);
    for(auto [x, y] : mp)
    {
        ll xx = x;
        while(xx)
        {
            vis[xx % 10]++;
            xx /= 10;
        }
        for(int i=1; i<=9; i++)
        {
            if(vis[i] == 0) continue;
            vis[i]--;
            solve();
            vis[i]++;
        }
        for(int i=1; i<10; i++) vis[i] = 0;
    }
    int t;
    cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        if(s == "0") {cout << "3677788889999" << "\n"; continue;}
        sort(s.begin(), s.end());
        ll tot = 0;
        for(int now : s) tot = tot * 10 + (now - '0');
        if(ans.count(tot))
            cout << ans[tot] << "\n";
        else
            cout << "impossible\n";
    }
    return 0;
}

标签:int,听牌,long,ICPC,vis,Mahjong,2022,include
From: https://www.cnblogs.com/dgsvygd/p/16910125.html

相关文章

  • 2022.11.20:ICPC合肥 打星
    打星\(5\)题铜昨天打了\(vp\)了一场威海铁,打着打着甚至还睡着了,没想到今天过题嘎嘎猛,不过是抱着打星的心态乱交题的来着开场一看标题,一眼\(A\)题签到题,我直接上机......
  • 2022 ICPC合肥 B Genshin Impact
    ProblemB.GenshinImpact概率考虑一段\(y\)中,被燃烧的时间段及其概率只需要计算会影响到这一段的射箭点燃火的概率即可也就是这一段\(y\)开头的那次射箭,以及上次......
  • Wust Java Club 2022-2023上半学年中期考核
    WustJavaClub2022-2023上半学年中期考核前言提交时的注意事项不可写入包名,如packageedu.wust必须有且只能有一个公有类publicclassMain,若有其他类,不应给其赋为......
  • 2022-2023-1 20221422 《计算机基础与程序设计》第十二周学习总结
    作业信息这个作业属于哪个课程<班级的链接>(https://edu.cnblogs.com/campus/besti/2022-2023-1-CFAP)这个作业要求在哪里<作业要求的链接>(https://www.cnblogs.......
  • 2022-2023-1 20221302《计算机基础与程序设计》第十二周学习总结
    作业信息这个作业属于那个班级 https://edu.cnblogs.com/campus/besti/2022-2023-1-CFAP作业要求  https://www.cnblogs.com/rocedu/p/9577842.html#WEEK12作业目标......
  • 2022-2023—1 20221306《计算机基础与程序设计》第十二周学习总结
    作业信息班级链接:https://edu.cnblogs.com/campus/besti/2022-2023-1-CFAP作业要求:https://www.cnblogs.com/rocedu/p/9577842.html#WEEK11作业目标:学习《C语言程序设计》......
  • 2022-11-20 Acwing每日一题
    本系列所有题目均为Acwing课的内容,发表博客既是为了学习总结,加深自己的印象,同时也是为了以后回过头来看时,不会感叹虚度光阴罢了,因此如果出现错误,欢迎大家能够指出错误,我......
  • NET7+c#11 2022.11.8日发布,新功能介绍
    c#11新功能原始字符串泛型特性net7新功能:use+add+required速率限制中间件:令牌桶固定窗口:2/s并发限制器用户限流的限制器:爬虫.NETMinimalAPI:没有控制器没有filte......
  • 2022.11.20
    T2:首先看出,答案肯定与\(X\)有关,所以肯定有一层循环用来枚举\(X\)然后考虑每个州对答案的贡献,只会是某个兵种的范围所以需要求出当前\(X\)下,某个兵种的范围,下面以......
  • 2022-2023-1 20221402 《计算机基础与程序设计》第十二周学习总结
    作业信息这个作业属于哪个课程<班级的链接>(如2022-2023-1-计算机基础与程序设计)这个作业要求在哪里<作业要求的链接>(如2022-2023-1计算机基础与程序设计第十二......