AC代码
1 //仔细思考如何降低时间复杂度,两次有什么区别 2 #include <stdio.h> 3 #include <stdlib.h> 4 int cmp(const void *a,const void *b) 5 { 6 int x = *(int*)a; 7 int y = *(int*)b; 8 return x-y; 9 } 10 int main () 11 { 12 int N; 13 int p; 14 scanf("%d %d",&N,&p); 15 long input[100000]; 16 int cnt = 0; 17 // float temp; //用于将最大最小比值与P做比较 18 int i; 19 int ret = 0; 20 for(i = 0;i < N;i++) 21 { 22 scanf("%ld",&input[i]); 23 } 24 qsort(input,N,sizeof(input[0]),cmp); 25 int j ; 26 for(i = 0;i < N;i++) 27 { 28 cnt = ret; 29 for(j = i + ret ;j < N;j++) 30 { 31 // temp = input[j] / input[i]; 32 if(input[j] <= input[i] * p) 33 { 34 cnt++; 35 }else 36 break; 37 } 38 if(cnt >ret) 39 { 40 ret = cnt; 41 } 42 } 43 printf("%d",ret); 44 return 0; 45 }