超时~花儿朵朵

 1 #include <stdio.h>

 2 #include <stdlib.h>

 3 #define M 100001

 4 

 5 struct time

 6 {

 7     int a;

 8     int b;

 9 }flower[M];

10 

11 int visit[M];

12 

13 int cmp(const void *x, const void *y)

14 {

15     struct time *m = (struct time *)x;

16     struct time *n = (struct time *)y;

17     return m->a - n->a;

18 }

19 

20 int main()

21 {

22     int ce, n, m, i, j, sum;

23     scanf("%d", &ce);

24     while(ce--){

25 

26             scanf("%d %d", &n, &m);

27             for(i = 1; i <= n; i++){

28 

29                     scanf("%d %d", &flower[i].a, &flower[i].b);

30 

31             }

32             qsort(flower+1, n, sizeof(flower[0]), cmp); 

33             for(i = 1; i <= m; i++){

34 

35                     sum = 0;

36                     scanf("%d", &visit[i]);

37                     for(j = 1; j <= n; j++){

38 

39                             if(visit[i] <= flower[j].b)

40                             {

41                                 break;    

42                             }

43                     

44                     }

45                     while(j <= n){

46 

47                             if(visit[i] < flower[j].a)

48                                 break;

49                             if(flower[j].a <= visit[i] && flower[j].b >= visit[i])

50                             {

51                                 sum++;

52                             }

53                             j++;

54 

55                     }

56                     printf("%d\n", sum);

57 

58             }

59             

60     }

61     return 0;

62 }
View Code

 

你可能感兴趣的:(超时)