2014
03-16

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

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.

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

#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

1. 你只是碰到了他们，他们并不想伤害你。所以你可以继续睡觉，他们也可以继续做事。如果你不睡，想去打扰他们反到不好了。就是在晚上的时候，无论听到什么声音，或看到什么，都尽量不要好奇。

2. #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 . 谁能解释下？

3. /*
* =====================================================================================
*
* Filename: 1366.cc
*
* Description:
*
* Version: 1.0
* Created: 2014年01月06日 14时52分14秒
* Revision: none
* Compiler: gcc
*
* Author: Wenxian Ni (Hello World~), niwenxianq@qq.com
* 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;
}