bnu 10809 聚餐

Lolilu大牛又要请客了~~
有些同学呢,是果断要去的,而有些同学呢,只有确定心中的大牛会参加,他才会参加。
Lolilu决定请大家去吃金钱豹,因此希望你告诉他一共会有多少人参加,他才知道带多少钱比较合适。假设金钱豹人均消费200元。

Input
第一行一个整数N(N<=100),表示一共多少个同学。
接下来N行依次描述了这N个同学,每行一个整数C表示该同学心中的大牛的编号。如果C为-1表示该同学果断要去。

Output
一个整数T,表示Lolilu大牛要出多少钱。

Sample Input
5
-1
1
2
5
4
Sample Output
800

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <algorithm>
 5 # include <cmath>
 6 # define LL long long
 7 using namespace std ;
 8 
 9 int a[200] ;
10 int b[200] ;
11 
12 int main()
13 {
14     //freopen("in.txt","r",stdin) ;
15     int n ;
16     while(scanf("%d" , &n) !=EOF)
17     {
18         int i ;
19         int sum = 0 ;
20         for (i = 1 ; i <= n ; i++)
21             scanf("%d" , &a[i]) ;
22         for (i = 1 ; i <= n ; i++)
23             if (a[i] == -1)
24             {
25                 b[i] = 1 ;
26                 sum++ ;
27             }
28         while(1)
29         {
30             bool flag = 1 ;
31             for (i = 1 ; i <= n ; i++)
32             {
33                 if (b[a[i]] && b[i] == 0)
34                 {
35                 b[i] = 1 ;
36                 sum++ ;
37                 flag = 0 ;
38                 }
39             }
40             if (flag)
41                 break ;
42         }
43 
44         printf("%d
" , (sum+1)*200) ;
45     }
46 
47     return 0 ;
48 }
View Code
原文地址:https://www.cnblogs.com/mengchunchen/p/4799029.html