poj3069
// // main.c // poj3069 // // Created by 韩雪滢 on 11/21/16. // Copyright © 2016 韩雪滢. All rights reserved. // #include <stdio.h> //#include <mm_malloc.h> #include "malloc.h" #include <stdlib.h> #include <time.h> int R; int N; int *points; int cmp(const void *a,const void *b){ return *(int*)a<*(int*)b?-1:1; } int main(int argc, const char * argv[]) { while(scanf("%d%d",&R,&N) && R!= -1 && N != -1){ int i,j; int temp = 0; int pN = 0; points = (int*)malloc(sizeof(int)*N); for(i=0;i<N;i++) scanf("%d",&points[i]); qsort(points,N,sizeof(int),cmp); while(temp<N-1){ for(j=temp;j<N;j++) { if(points[j] > points[temp]+R){ temp=j; pN++; break; } } } printf("%d\n",pN); } return 0; }
不知道为什么超时
如果有更好的改进方法请不吝赐教