u010510549 于 2013.12.31 23:12 提问

1
6 2
4 6 6 1 -1 3 1
5 -1 3 2 -1 -1 2
hehe

2

#include

using namespace std;
int a[1001][1001],c[1001],vote2[1001];
int vote[1001];
bool victory;
string s;
int last;
int countn(int n,int k){
for(int i =1;i<=n;i++)
if(c[i]==0){
int j=0;
for(;j<k;j++){
if(a[j][i]==-1){j=k;break; }
if(a[j][i]!=a[j][last]) break;
}
c[i]=j==k;

``````}
``````

int num=0;
for(int i =1;i<=n;i++)
if(c[i]==1) {num++;
}
return num;
}

int deal(int n,int k)
{
for(int i=0; i<k; i++)
c[a[i][0]]=-1;
for(int i=1; i<=n; i++)if(a[k-1][i]!=-1)
vote[a[k-1][i]]++;

``````if(victory)
{

int maxn=0;
for(int i=1; i<=n; i++)
if(vote[i]>vote[maxn])  maxn=i;

if(maxn!=0)
{
c[maxn]=-1;

for(int i=1; i<=n; i++)
{
if(a[k-1][i]!=-1&&i!=maxn){ c[i]=1;
last=i;

}
}
}
else
{   int maxn=0;
for(int i=1; i<=n; i++)if(a[k-2][i]!=-1)
vote2[a[k-2][i]]++;

for(int i=1; i<=n; i++)
if(vote2[i]>vote2[maxn])  maxn=i;

for(int i=1; i<=n; i++)
{
if(a[k-2][i]!=-1&&i!=a[k-1][0]&&i!=maxn) {c[i]=1;

last=i;

}
}

}
}
else
{

int maxn=0;
for(int i=1; i<=n; i++)
if(vote[i]>vote[maxn])  maxn=i;

c[maxn]=1;
``````

last=maxn;
for(int i=1;i<=n;i++)
if(a[k-1][i]!=-1&&i!=maxn) c[i]=-1;

``````    }

return countn(n,k);
}

int main()
{
int t,n,k;
cin>>t;
while(t--)
{
cin>>n>>k;
memset(c,0,sizeof(c));
memset(vote,0,sizeof(vote));
memset(vote2,0,sizeof(vote2));
for(int i=0; i<k; i++)
for(int j=0; j<=n; j++)
cin>>a[i][j];
cin>>s;
victory=(s=="haha");

cout<< deal(n,k)<<endl;

}
return 0;
}
``````