# An Unfair Game-[ACdream1035]

#### Problem Description

There are n people and n target, everyone should get one target, no two people get the same target, the last one who get the target should be punished, there is only one person will be punished, so if more than one person are the last, no one will be punished. As the judge, you know exactly how much time that people i getting target j will spend, but there are no people know how much time he needs. You need to arrange for a target to everyone, and you want the i-th people to be punished (Now you know why it is an unfair game?).

#### Input

The input contains several test, and ends with EOF. For each test, the first line has an integer n,which is the number of people and target,next there is an integer matrix which size is n*n, the i-th row and the j-th colume of matrix means the time that i-th person needs to get target j. Next line is a number m, the number of the person who you want to be punished.

1<=m<n<=100

#### Output

Each test print one line, the number of the target that m-th person gets, if there are more than one answer, print all of them. If there is no answer, only print -1.

3
1 2 3
2 3 4
3 4 5
3
3
3 3 3
2 2 2
1 1 1
3

2 3
-1

UUZ

#### Manager

``` 1 #include<stdio.h>
2 #include<string.h>
3 int d[120][120],res[120],N,M,q[120];
4 bool f[120][120],sta[120];
5 bool find(int a)
6 {
7     for (int i=1;i<=N;i++)
8     {
9         if (f[a][i] && (!sta[i]))
10         {
11             sta[i]=true;
12             if (res[i]==0 || find(res[i]))
13             {
14                 res[i]=a;
15                 return true;
16             }
17         }
18     }
19     return false;
20 }
21 int hungary()
22 {
23     memset(res,0,sizeof(res));
24     int Ans=0;
25     for (int i=1;i<=N;i++)
26     {
27         memset(sta,0,sizeof(sta));
28         if (find(i)) Ans++;
29     }
30     return Ans;
31 }
32 int main()
33 {
34     while (scanf("%d",&N)!=EOF)
35     {
36         for (int i=1;i<=N;i++)
37             for (int j=1;j<=N;j++)
38                 scanf("%d",&d[i][j]);
39         scanf("%d",&M);
40         int T=0;
41         for (int i=1;i<=N;i++)
42         {
43             memset(f,true,sizeof(f));
44             for (int j=1;j<=N;j++) f[j][i]=false;
45             for (int j=1;j<=N;j++) f[M][j]=false;
46             for (int j=1;j<=N;j++)
47                 for (int k=1;k<=N;k++)
48                     if (d[j][k]>=d[M][i]) f[j][k]=false;
49             if (hungary()==(N-1)) q[++T]=i;
50         }
51         if (T==0) printf("-1\n");
52         else
53         {
54             for (int i=1;i<T;i++) printf("%d ",q[i]);
55             printf("%d\n",q[T]);
56         }
57     }
58     return 0;
59 }```
View Code

An Unfair Game-[ACdream1035],布布扣,bubuko.com

An Unfair Game-[ACdream1035]

(0)
(0)