L1-020. 帅到没朋友

题目链接:https://www.patest.cn/contests/gplt/L1-020

思路:储存输入的N,K,M将每个id保存,再输入查询的id,判断储存的数组中是否有此id,无输出。

注意点:情况考虑完全。

(1)如果一个朋友圈只有一个人,则该朋友是无朋友的,只要K>2这个朋友就是有朋友的,

(2)输入查询的id可以多次输入,当只输出一次,所以需要查询该id是否已经输出过(或查询过)。

最后一个测试点超时了!!!!!!!!!

 1 #include<stdio.h>
 2 int main(){
 3     int N,i,j;
 4     int str[100][1000];
 5     scanf("%d",&N);
 6     for(i=0;N>0;i++){
 7         scanf("%d",&str[i][0]);
 8         if(str[i][0]==1){             //保证所有K超过1的朋友圈里都至少有2个不同的人
 9             i--;
10             int x;
11             scanf("%d",&x);      //读入x,防止下次被当做下一个n读入 
12             goto next1;
13         }
14         for(j=1;str[i][0]>0;j++)
15         {
16             int k,a;
17             scanf("%d",&str[i][j]); 
18             for(k=1;k<j;k++)
19             {
20                 if(str[i][k]==str[i][j])         //已经输入过 
21                 { 
22                     j--;
23                     break; 
24                 }
25             }
26             str[i][0]--;      
27         }
28         str[i][0]=j-1;         //朋友个数 
29         next1:N--;
30     }
31     N=i;
32     int M,num,cx[10000];
33     num=0;
34     scanf("%d",&M);
35     while(M){
36         int a;
37         scanf("%d",&a);
38         for(i=0;i<N;i++){
39             for(j=1;j<=str[i][0];j++){
40                 if(a==str[i][j])           //有朋友 
41                     goto next;
42             }
43         }
44         int l;
45         for(l=0;l<num;l++)           //查找过 
46         {
47             if(a==cx[l])goto next;
48         }
49         cx[num]=a;
50         num++;
51         next:M--;
52     }
53     if(num==0)printf("No one is handsome\n");
54     else
55     {
56        // printf("%d\n",num);
57         for(i=0;i<num;i++){
58             printf("%05d",cx[i]);
59             if(i<num-1)printf(" ");
60         }
61         printf("\n");
62     }
63     return 0;
64 } 

 

posted @ 2018-01-19 15:06  爱你的笑  阅读(269)  评论(0编辑  收藏  举报