日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

2019计蒜之道 B:个性化评测系统

發布時間:2025/4/16 windows 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2019计蒜之道 B:个性化评测系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

比賽的時候沒有想清楚,直接排序然后從前向后dfs,一直卡著,就是沒有想到其他的情況。其實有可能是223344這樣的,最后寫的時候忘記處理了222233334444情況,還是看別人博客才發現的。還是太菜了,繼續努力。

?

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#define ll long long

using namespace std;

char mian[10]="mspz";
map<string,int> majong[4];
map<string,int>::iterator itr;
string tmp;
int cnt[4][14];

int dfs(int x,int c1,int c2)
{
??? int i,j,flag=0;
??? if(c1==4 && c2==1)
??????? return 1;
??? else if(c1>4 || c2>1 || x>=14)
??????? return 0;
??? if(c2==0)
??? {
??????? for(i=0;i<4;i++)
??????????? for(j=1;j<=9;j++)
??????????????? if(cnt[i][j]>=2)
??????????????? {
??????????????????? cnt[i][j]-=2;
??????????????????? flag|=dfs(x+2,c1,c2+1);
??????????????????? cnt[i][j]+=2;
??????????????????? if(flag)
??????????????????????? return 1;
??????????????? }
??????? return 0;
??? }
??? else
??? {
??????? for(i=0;i<4;i++)
??????????? for(j=1;j<=9;j++)
??????????? {
??????????????? if(cnt[i][j]==0)
??????????????????? continue;
??????????????? else if(cnt[i][j]==1)
??????????????? {
??????????????????? if(i!=3 && cnt[i][j+1]>0 && cnt[i][j+2]>0)
??????????????????? {
??????????????????????? cnt[i][j]--,cnt[i][j+1]--,cnt[i][j+2]--;
??????????????????????? flag|=dfs(x+3,c1+1,c2);
??????????????????????? cnt[i][j]++,cnt[i][j+1]++,cnt[i][j+2]++;
??????????????????????? if(flag)
??????????????????????????? return 1;
??????????????????? }
??????????????????? else
??????????????????????? return 0;
??????????????? }
??????????????? else if(cnt[i][j]==2)
??????????????? {
??????????????????? if(i!=3 && cnt[i][j+1]>=2 && cnt[i][j+2]>=2)
??????????????????? {
??????????????????????? cnt[i][j]-=2,cnt[i][j+1]-=2,cnt[i][j+2]-=2;
??????????????????????? flag|=dfs(x+6,c1+2,c2);
??????????????????????? cnt[i][j]+=2,cnt[i][j+1]+=2,cnt[i][j+2]+=2;
??????????????????????? if(flag)
??????????????????????????? return 1;
??????????????????? }
??????????????????? else
??????????????????????? return 0;
??????????????? }
??????????????? else if(cnt[i][j]==3)
??????????????? {
??????????????????? cnt[i][j]-=3;
??????????????????? flag|=dfs(x+3,c1+1,c2);
??????????????????? cnt[i][j]+=3;
??????????????????? if(flag)
??????????????????????? return 1;
??????????????????? if(i!=3 && cnt[i][j+1]==3 && cnt[i][j+2]==3)
??????????????????? {
??????????????????????? cnt[i][j]-=3,cnt[i][j+1]-=3,cnt[i][j+2]-=3;
??????????????????????? flag|=dfs(x+9,c1+3,c2);
??????????????????????? cnt[i][j]+=3,cnt[i][j+1]+=3,cnt[i][j+2]+=3;
??????????????????????? if(flag)
??????????????????????????? return 1;
??????????????????? }
??????????????????? else
??????????????????????? return 0;
??????????????? }
??????????????? else if(cnt[i][j]==4)
??????????????? {
??????????????????? cnt[i][j]-=3;
??????????????????? flag|=dfs(x+3,c1+1,c2);
??????????????????? cnt[i][j]+=3;
??????????????????? if(flag)
??????????????????????? return 1;
??????????????????? if(i!=3 && cnt[i][j+1]==4 && cnt[i][j+2]==4)
??????????????????? {
??????????????????????? cnt[i][j]-=4,cnt[i][j+1]-=4,cnt[i][j+2]-=4;
??????????????????????? flag|=dfs(x+12,c1+3,c2);
??????????????????????? cnt[i][j]+=4,cnt[i][j+1]+=4,cnt[i][j+2]+=4;
??????????????????????? if(flag)
??????????????????????????? return 1;
??????????????????? }
??????????????????? else
??????????????????????? return 0;
??????????????? }
??????????? }
??? }
}

inline void add(string t)
{
??? switch(t[1])
??? {
??? case 'm':
??????? cnt[0][t[0]-'0']++; break;
??? case 's':
??????? cnt[1][t[0]-'0']++; break;
??? case 'p':
??????? cnt[2][t[0]-'0']++; break;
??? case 'z':
??????? cnt[3][t[0]-'0']++; break;
??? };
}

inline int check()
{
??? int i,j;
??? for(i=0;i<4;i++)
??????? for(j=1;j<=9;j++)
??????????? if(cnt[i][j]>4)
??????????????? return 0;
??? return 1;
}

int main()
{
??? int i,j;
??? string str;
??? while(cin>>str)
??? {
??????? memset(cnt,0,sizeof(cnt));
??????? add(str);
??????? for(i=0;i<12;i++)
??????????? cin>>str, add(str);
??????? /*for(i=0;i<4;i++)
??????? {
??????????? for(j=1;j<=9;j++)
??????????????? cout<<cnt[i][j]<<' ';
??????????? cout<<endl;
??????? }*/

??????? for(i=0;i<3;i++)
??????????? for(j=1;j<=9;j++)
??????????? {
??????????????? tmp="";
??????????????? tmp+='0'+j;
??????????????? tmp+=mian[i];
??????????????? cnt[i][j]++;
??????????????? if(check() && dfs(0,0,0))
??????????????????? cout<<tmp<<endl;
??????????????? cnt[i][j]--;
??????????? }
??????? for(j=1;j<=7;j++)
??????? {
??????????? tmp="";
??????????? tmp+='0'+j;
??????????? tmp+=mian[3];
??????????? cnt[3][j]++;
??????????? if(check() && dfs(0,0,0))
??????????????? cout<<tmp<<endl;
??????????? cnt[3][j]--;
??????? }
??? }
??? return 0;
}


/*

1s 2s 3s 4s 5s 6s 7s 8s 9s 1z 1z 3p 4p


*/

?

轉載于:https://www.cnblogs.com/canchan/p/11072521.html

總結

以上是生活随笔為你收集整理的2019计蒜之道 B:个性化评测系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。