zoukankan      html  css  js  c++  java
  • Hrbust-1014 San Guo Sha(模拟)

    Description
    San Guo Sha is a popular Board Game. There are four kinds of cards: identity, role, life and magic card. Today we just regard the identity cards. There are four kinds of identity: Lord(ZG), Loyal minister(ZC), Provocateur(NJ) and Rebel(FZ). To win the game Lord and Loyal minister ‘s goal is make all of Provocateur and rebel dead, Rebel’s goal is make Lord dead, Provocateur’s goal is to be the last survivor. If Load dead and there’s only one Provocateur then he wins (just one Provocateur win), others Rebels win.
    In the standard contest, there are score rule:(If you know Chinese, could see the second picture)
    这里写图片描述
    The last score equal basic score plus extra score. Now I will tell the identity of everyone and who killed who, please compute everyone’ last score.

    Input
    On the first line of input is a single positive integer, 1<=T<=100, specifying the number of test cases to follow.
    Each test case begins with 2 integers N , M (4<=N<=100, 0<=M Then N string on next line(“ZG”,”ZC”,”FZ”,”NJ”), specifying each’s identity(begin with 0). I promise each identity will be at least one and there is one and only one ZG.
    Then M lines follow, each line with two numbers A B, meaning A killed B.I promise A and B must alive player. If someone was win then you should not deal with the remain instruct.

    Output
    Please output the everyone’s last score in a line, n integers separate by a blank space.
    Sample Input
    3
    4 3
    ZG ZC NJ FZ
    1 3
    2 1
    0 2

    6 1
    ZG ZC NJ FZ FZ FZ
    3 0

    8 7
    ZG ZC ZC NJ NJ FZ FZ FZ
    3 1
    3 2
    3 4
    3 5
    3 6
    3 7
    3 0
    Sample Output
    5 6 4 0
    0 0 1 11 9 9
    1 0 0 20 0 0 0 0
    Hint
    当以下任意一种情况发生时,游戏将立即结束:
    1.ZG被杀。
    此时,若某NJ是唯一存活的角色,则该NJ获胜。否则FZ(不论死活)获胜。
    2.所有的FZ和NJ都已死亡:ZG和ZC(不论死活)都获胜。

    1.ZG与NJ单挑的定义:此时只有ZG和该NJ存活,其他角色都已死亡。
    2.某NJ胜利的时候,其他NJ没分数

    一个模拟三国杀计分规则的题。。。对于一个不会玩三国杀的人来说头都要炸了。基本上就对规则进行模拟,注意一些坑点,比如主公死了一切都结束了,在计分上也会有一些影响。比较奇怪的是,这道题在HrbustOJ和HDU里都有,而且题面一模一样,可是这个代码只能过HrbustOJ上的,而过不了HDU的题,你可能会说Hrbust数据水,可是听说之前有人能过HDU的这题却过不了Hrbust的,数据难道是各有所长?还是其中一个有错?因为题面一样所以不得而知。

    #include<stdio.h>
    #include<string.h>
    struct man
    {
        int num;
        char name[3];
        bool life;
    } a[108];
    int main()
    {
        int t,n,m;
        scanf("%d",&t);
        while(t--)
        {
            int fz=0,zc=0,nj=0,njj=-1;///因为各个角色从0开始,因此不存在的位置应该被定为-1而不是0
            bool zgg=false,fzz=false;
            scanf("%d%d",&n,&m);
            for(int i=0; i<n; i++)
            {
                scanf("%s",a[i].name);
                a[i].num=0;
                a[i].life=true;
                if(a[i].name[1]=='Z')fz++;
                if(a[i].name[1]=='C')zc++;
                if(a[i].name[1]=='J')nj++;
            }
            int x[109],y[109];
            for(int q=1;q<=m;q++)
            {
                scanf("%d%d",&x[q],&y[q]);
            }
            for(int q=1;q<=m;q++)
            {
                if(a[y[q]].name[1]=='G')///主公被杀
                {
                    a[y[q]].life=false;
                    if(a[x[q]].name[1]=='Z')///反贼杀死主公必定反贼赢
                    {
                        a[x[q]].num+=2;
                        fzz=true;
                    }
                    if(a[x[q]].name[1]=='J')
                    {
                        if(nj==1&&fz==0&&zc==0)///内奸只有通过和主公单挑才能赢,因此仅仅是当剩余1个内奸和1个主公时才判定内奸杀主公时内奸赢,否则是反贼赢
                        {
                            a[x[q]].num+=4+n*2;
                            njj=x[q];///记录最终杀死主公的是哪位内奸,算分时只有这个内奸得分
                        }
                        else
                        {
                            fzz=true;
                        }
                    }///忠臣不会杀主公
                    break;
                }
                if(a[y[q]].name[1]=='C')///忠臣被杀
                {
                    zc--;
                    a[y[q]].life=false;
                    if(a[x[q]].name[1]=='Z')///只有被反贼杀才有额外加分
                    {
                        a[x[q]].num++;
                    }
                }
                if(a[y[q]].name[1]=='J')///内奸被杀
                {
                    if(a[x[q]].name[1]=='G')///内奸被主公杀时判断是否是单挑情况
                    {
                        if(nj==1&&zc==0&&fz==0)
                        {
                            a[y[q]].num=n;///如果单挑,那么记录这个单挑的内奸,分数单独被定为n
                            njj=y[q];
                        }
                    }
                    nj--;
                    a[y[q]].life=false;
                    if(a[x[q]].name[1]!='J')a[x[q]].num++;///内奸可能被内奸杀,只有不被内奸杀时才有额外加分
                    if(nj==0&&fz==0)
                    {
                        zgg=true;
                        break;
                    }
                }
                if(a[y[q]].name[1]=='Z')///反贼被杀
                {
                    fz--;
                    a[y[q]].life=false;
                    if(a[x[q]].name[1]!='J'&&a[x[q]].name[1]!='Z')///反贼会被反贼杀,因此反贼只被忠臣和主公杀时加分
                    {
                        a[x[q]].num++;
                    }
                    if(nj==0&&fz==0)
                    {
                        zgg=true;
                        break;
                    }
                }
            }
            if(zgg)///主公赢
            {
                for(int i=0; i<n; i++)
                {
                    if(a[i].name[1]=='G')
                    {
                        printf("%d%c",a[i].num+4+zc*2,i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='C')
                    {
                        printf("%d%c",a[i].num+5+zc,i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='Z')
                    {
                        printf("0%c",i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='J')
                    {
                        printf("%d%c",i==njj?a[i].num:0,i==n-1?'
    ':' ');///主公赢时,单挑的内奸有分,否则为0分
                    }
                }
            }
            else if(njj!=-1&&!zgg)///内奸赢
            {
                for(int i=0; i<n; i++)
                {
                    if(a[i].name[1]=='G')
                    {
                        printf("%d%c",1,i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='C')
                    {
                        printf("0%c",i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='Z')
                    {
                        printf("0%c",i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='J')
                    {
                        printf("%d%c",i==njj?a[i].num:0,i==n-1?'
    ':' ');///内奸赢时,只有单挑的内奸有分,其余0分
                    }
                }
            }
            else if(fzz)///反贼赢
            {
                for(int i=0; i<n; i++)
                {
                    if(a[i].name[1]=='G')
                    {
                        printf("0%c",i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='C')
                    {
                        printf("0%c",i==n-1?'
    ':' ');
                    }
                    if(a[i].name[1]=='Z')
                    {
                        a[i].num+=fz*3;
                        printf("%d%c",a[i].num,i==n-1?'
    ':' ');///反贼都有分,在额外加分的基础上加基础得分
                    }
                    if(a[i].name[1]=='J')
                    {
                        printf("%d%c",a[i].life?1:0,i==n-1?'
    ':' ');///只有活着的内奸有1分,否则为0分
                    }
                }
            }
        }
    }
    /*
    1)主公死亡。此时若内奸是唯一存活的角色(有且仅有一名内奸存活),则内奸获胜,除此之外的情况为反贼获胜(不论反贼角色死活)。
    2)所有的反贼和内奸都已死亡:主公和忠臣(不论死活)都获胜。
    */
    
  • 相关阅读:
    H5图片上传、压缩
    数据库基本操作
    数组遍历
    CURL
    获取IP
    Memcached的实战笔记
    修bug总结 (基于java语言)
    java开发工作的总结
    多线程测试类
    可清除的单例对象获取类
  • 原文地址:https://www.cnblogs.com/kuronekonano/p/11135819.html
Copyright © 2011-2022 走看看