题目信息:
2 2 8 6 1 1 4 5 2 10 6 4 5 6 5
1 2
源码
#include <stdio.h> #include <math.h> #include <stdlib.h> struct QJ { double x, y; }qj[10000]; int cmp(const void* x, const void* y) { if ((*(QJ*)x).x == (*(QJ*)y).x) return (*(QJ*)x).y - (*(QJ*)y).y; else return (*(QJ*)x).x - (*(QJ*)y).x; } int sel(double e, int used) { int s = 0; double b = 0, max = 0; while (b < e) { max = 0; for (int k = 0; k < used && qj[k].x <= b; ++k) { if (qj[k].y - b > max) max = qj[k].y - b; } if (0 == max) return 0; b += max; s++; } return s; } int main() { int M, N, i, j, k, num, used; int length, width; scanf ("%d",&M); while(M--) { used = 0; scanf ("%d%d%d",&N, &length, &width); for (i = 0; i < N; i++) { scanf("%d%d", &j, &k); if (k * 2 >= width) { double t = sqrt((double)(k*k - width*width / 4)); qj[used].x = j - t; qj[used++].y = j + t; } } qsort(qj, used, sizeof(qj[0]), cmp); //for (i = 0; i < used; i++) // printf("(%.1lf, %.1lf) ", qj[i].x, qj[i].y); num = sel(length, used); printf("%d\n", num); } return 0; }
原文地址:http://blog.csdn.net/xianyun2009/article/details/39369613