ccf -201909-2

*主要注意的点是:要特判以n-1、n、1是否连续掉落(以n为中间);以及n、1、2是否连续掉落(以n为开头)

 1 #include <stdio.h>
 2 #define MAX 1005
 3 
 4 using namespace std;
 5 
 6 struct Node{
 7     int apple;
 8     bool flag;
 9 };
10 
11 
12 int main(){
13     Node tree[MAX];
14     int n,m,x;
15     int sum,count,three;
16     while(scanf("%d",&n)!=EOF){
17         sum=count=three=0;
18         for(int i=1;i<=n;i++){
19             tree[i].flag=false;
20             tree[i].apple=0;
21         }
22         for(int i=1;i<=n;i++){
23             scanf("%d",&m);
24             for(int j=1;j<=m;j++){
25             scanf("%d",&x);
26             if(j>1 && x>0 && x<=tree[i].apple){
27                 //count++;
28                 if(x<tree[i].apple)    tree[i].flag=true;
29                 tree[i].apple=x;
30             }    
31             else    tree[i].apple+=x;
32             }
33         }
34         for(int i=1;i<=n;i++){
35             sum+=tree[i].apple;
36             if(tree[i].flag)    count++;
37             if(i>=2 && i<=n-1 &&tree[i-1].flag && tree[i].flag && tree[i+1].flag)        //含有以n为结尾 
38                 three++;
39         }
40         //特判 
41         if(tree[n-1].flag && tree[n].flag && tree[1].flag)        //以n为中间 
42             three++;
43         if(tree[n].flag && tree[1].flag && tree[2].flag)        //以n为开头 
44             three++;
45         printf("%d %d %d\n",sum,count,three);
46         
47     }
48     return 0;
49 }

猜你喜欢

转载自www.cnblogs.com/shiliuxinya/p/12019868.html