1218. Episode N-th: The Jedi Tournament(bfs)

1218

简答题

对于当前点 判断每个点是否可达

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 #include<stdlib.h>

 6 #include<vector>

 7 #include<queue>

 8 #include<string>

 9 using namespace std;

10 vector<int>ed[210];

11 int w[210][210],vis[210];

12 struct node

13 {

14     char s[35];

15     int a,b,c;

16 }p[210];

17 int judge(int x,int y)

18 {

19     int a1 = p[x].a,a2 = p[x].b,a3 = p[x].c;

20     int a4 = p[y].a,a5 = p[y].b,a6 = p[y].c;

21     int o=0;

22     if(a1>a4)

23     o++;

24     if(a2>a5)

25     o++;

26     if(a3>a6)

27     o++;

28     if(o>=2)

29     return 1;

30     return 0;

31 }

32 int spfa(int e,int s)

33 {

34     int i;

35     memset(vis,0,sizeof(vis));

36     queue<int>q;

37     q.push(s);

38     vis[s] = 1;

39     while(!q.empty())

40     {

41         int u = q.front();

42         w[u][s] = 1;

43         q.pop();

44         for(i = 0 ;i < (int)ed[u].size() ; i++)

45         {

46             int v = ed[u][i];

47             if(!vis[v])

48             {

49                 vis[v] = 1;

50                 q.push(v);

51             }

52         }

53     }

54     if(w[e][s])

55     return 1;

56     return 0;

57 }

58 int main()

59 {

60     int i,j,n;

61     scanf("%d",&n);

62     for(i = 1; i <= n ; i++)

63     {

64         cin>>p[i].s>>p[i].a>>p[i].b>>p[i].c;

65     }

66     for(i = 1; i <= n ;i++)

67     {

68         for(j = 1; j <= n ; j++)

69         {

70             if(i==j)

71             continue;

72             if(judge(i,j))

73             {

74                 w[i][j] = 1;

75                 ed[j].push_back(i);

76             }

77         }

78     }

79     for(i = 1; i <= n ;i++)

80     {

81         int flag = 1;

82         for(j = 1 ; j <= n ;j++)

83         {

84             if(i==j)

85             continue;

86             if(!w[i][j]&&!spfa(i,j))

87             {

88                 flag = 0;

89                 break;

90             }

91         }

92         if(flag)

93         printf("%s\n",p[i].s);

94     }

95     return 0;

96 }
View Code

 

你可能感兴趣的:(name)