首页 > ACM题库 > HDU-杭电 > HDU 3378-San Guo Sha-模拟-[解题报告]HOJ
2014
03-16

HDU 3378-San Guo Sha-模拟-[解题报告]HOJ

San Guo Sha

问题描述 :

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.
Plan

Plan

In the standard contest, there are score rule:(If you know Chinese, could see the second picture)
PlanPlan
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.

输入:

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<N). N is the number of players and M is the relation of who kill who.
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.

输出:

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<N). N is the number of players and M is the relation of who kill who.
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.

样例输入:

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

样例输出:

5 6 4 0
0 0 1 11 9 9
1 0 0 20 0 0 0 0

http://acm.hdu.edu.cn/showproblem.php?pid=3378

规则去玩三国杀就理解了

纯模拟

注意的点:有已经分出胜负但还在杀的情况出现,所以要每次杀操作前判断是否分出胜负,如果已经分出胜负了就continue,不用接着往下操作

San Guo Sha

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std ;
int n ;
typedef struct L{
    char js[5] ;
    int al ;
    int esc ;
    int sc ;
}L ;
L kk[101] ;
int pk ;
int bjnj,wnj ;
int ok()
{
    int f=0 ;
    int cntfz=0 ;
    int cntnj=0 ;
    int cntzc=0 ;
    for(int i=0 ;i<n ;i++)
    {
        if(!strcmp(kk[i].js,"ZG"))
        {
            if(kk[i].al)
                f=1 ;
        }
        if(!strcmp(kk[i].js,"FZ"))
        {
            if(kk[i].al)
                cntfz++ ;
        }
        if(!strcmp(kk[i].js,"NJ"))
        {
            if(kk[i].al)
            {
                bjnj=i ;
                cntnj++ ;
            }
        }
        if(!strcmp(kk[i].js,"ZC"))
        {
            if(kk[i].al)
                cntzc++ ;
        }
    }
    if(!(cntzc+cntfz) && cntnj==1 && f)
    {
        pk=1 ;
        wnj=bjnj ;
    }
    if(!(cntfz+cntnj))
    {
        if(pk)
        {
            kk[wnj].sc=n ;
        }
        for(int i=0 ;i<n ;i++)
        {
            if(!strcmp(kk[i].js,"ZG"))
                kk[i].sc=4+cntzc*2+kk[i].esc ;
            if(!strcmp(kk[i].js,"ZC"))
                kk[i].sc=5+cntzc+kk[i].esc ;
        }
        return 1 ;
    }
    if(!f)
    {
        if(cntnj==1 && cntfz==0 && cntzc==0)
        {
            for(int i=0 ;i<n ;i++)
            if(!strcmp(kk[i].js,"ZG"))
                kk[i].sc=1 ;
            kk[wnj].sc=4+n*2 ;
            return 1 ;
        }
        for(int i=0 ;i<n ;i++)
        {
            if(!strcmp(kk[i].js,"NJ"))
                if(kk[i].al)
                    kk[i].sc=1 ;
            if(!strcmp(kk[i].js,"FZ"))
                kk[i].sc=cntfz*3+kk[i].esc ;
        }
        return 1 ;
    }
    return 0 ;
}
int main()
{
    int t ;
    scanf("%d",&t) ;
    while(t--)
    {
        int m ;
        scanf("%d%d",&n,&m) ;
        for(int i=0 ;i<n ;i++)
        {
            scanf("%s",kk[i].js) ;
            kk[i].al=1 ;
            kk[i].esc=0 ;
            kk[i].sc=0 ;
        }
        pk=0 ;
        for(int i=0 ;i<m ;i++)
        {
            int a,b ;
            scanf("%d%d",&a,&b) ;
            if(ok())
                continue ;
            kk[b].al=0 ;
            if(!strcmp(kk[a].js,"FZ") && (!strcmp(kk[b].js,"ZG")))
            {
                kk[a].esc+=2 ;
            }
            if(!strcmp(kk[a].js,"FZ") && (!strcmp(kk[b].js,"ZC")))
            {
                kk[a].esc++ ;
            }
            if(!strcmp(kk[a].js,"FZ") && (!strcmp(kk[b].js,"NJ")))
            {
                kk[a].esc++ ;
            }
            if(!strcmp(kk[a].js,"ZG") && (!strcmp(kk[b].js,"FZ")))
            {
                kk[a].esc++ ;
            }
            if(!strcmp(kk[a].js,"ZG") && (!strcmp(kk[b].js,"NJ")))
            {
                kk[a].esc++ ;    
            }
            if(!strcmp(kk[a].js,"ZC") && (!strcmp(kk[b].js,"FZ")))
            {
                kk[a].esc++ ;    
            }
            if(!strcmp(kk[a].js,"ZC") && (!strcmp(kk[b].js,"NJ")))
            {
                kk[a].esc++ ;    
            }
        }
        ok() ;
        for(int i=0 ;i<n ;i++)
        {
            if(!i)
                printf("%d",kk[i].sc) ;
            else
                printf(" %d",kk[i].sc) ;
        }
        putchar('\n') ;
    }
    return 0 ;
}

View Code

 

参考:http://www.cnblogs.com/xiaohongmao/p/3505626.html


  1. #include <stdio.h>
    int main(void)
    {
    int arr[] = {10,20,30,40,50,60};
    int *p=arr;
    printf("%d,%d,",*p++,*++p);
    printf("%d,%d,%d",*p,*p++,*++p);
    return 0;
    }

    为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下?

  2. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }