欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

占卜DIY Page48 模拟

程序员文章站 2024-03-19 09:50:16
...

占卜DIY Page48 模拟

数组模拟链表,取头取尾加头加尾四种操作

把区间在一开始定义为[100,100][100,100]可以不用考虑区间边界取到负数,比如p[i].a[2]p[i].a[-2]

用数字的正和负表示是否为正面,省去了一个bool数组

#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<map>
#define ll long long
#define pb push_back
#define rep(x,a,b) for (int x=a;x<=b;x++)
#define repp(x,a,b) for (int x=a;x<b;x++)
#define W(x) printf("%d\n",x)
#define WW(x) printf("%lld\n",x)
#define pi 3.14159265358979323846
#define mem(a,x) memset(a,x,sizeof a)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
const int maxn=2e6+7;
const int INF=1e9;
const ll INFF=1e18;
struct node
{
    int l,r;
    int a[300];
}p[15];//左闭右开
int ans[20],cnt=0,knum=0;
char c[3];
int main()
{
    rep(i,1,13)p[i].l=p[i].r=100;
    rep(i,1,13)
    {
        rep(j,1,4)
        {
            scanf("%s",c);
            if (c[0]=='A')p[i].a[p[i].r++]=1;
            else if (c[0]=='0')p[i].a[p[i].r++]=10;
            else if (c[0]=='J')p[i].a[p[i].r++]=11;
            else if (c[0]=='Q')p[i].a[p[i].r++]=12;
            else if (c[0]=='K')p[i].a[p[i].r++]=13;
            else p[i].a[p[i].r++]=c[0]-'0';
            getchar();
        }
    }
    while(knum<4)
    {
        int top=p[13].a[p[13].l++];
        if (abs(top)==13)knum++;
        else
        {
            while(abs(top)!=13)
            {
                p[abs(top)].a[--p[abs(top)].l]=-abs(top);
                top=p[abs(top)].a[--p[abs(top)].r];
            }
            knum++;
        }
    }
    rep(i,1,13)
        rep(j,p[i].l,p[i].r-1)
            if (p[i].a[j]<0)
                ans[-p[i].a[j]]++;
    rep(i,1,12)if (ans[i]==4)cnt++;
    W(cnt);
    return 0;
}