标签:
2
2 8 6
1 1
4 5
2 10 6
4 5
6 5
1
2
1 #include <stdio.h> 2 #include <math.h> 3 4 int main(int argc, const char * argv[]) { 5 int m, n; 6 int w, h; 7 float from[10001], to[10001]; 8 scanf("%d", &m); 9 while (m--) { 10 scanf("%d %d %d", &n, &w, &h); 11 int k = 1; 12 float x, r, t = h * 1.0 / 2, sq; 13 for (int i = 0; i < n; i++) { 14 scanf("%f %f", &x, &r); 15 sq = sqrt(r * r - t * t); 16 if (r > t) { 17 from[k] = x - sq; 18 to[k++] = x + sq; 19 } 20 } 21 //排序 首要关键词 from 次要关键词 to 22 for (int i = 1; i < k - 1; i++) { 23 for (int j = i + 1; j < k; j++) { 24 if (from[i] > from[j] || (from[i] == from[j] && to[i] < to[j])) { 25 float temp = from[i]; 26 from[i] = from[j]; 27 from[j] = temp; 28 temp = to[i]; 29 to[i] = to[j]; 30 to[j] = temp; 31 } 32 } 33 } 34 //判断区间头部是否覆盖 35 if (from[1] > 0) { 36 printf("0\n"); 37 continue; 38 } 39 int ans = 1; 40 float flagT = to[1], flag = to[1]; 41 from[k] = w; 42 for (int i = 2; i < k; i++) { 43 if (from[i] <= flagT && to[i] > flagT && to[i] > flag) { //查找相对较大的区间 44 flag = to[i]; 45 } 46 if (from[i + 1] > flagT) { 47 flagT = flag; 48 ans++; 49 } 50 } 51 if (flagT < w) { //判断区间尾部是否覆盖 52 printf("0\n"); 53 } 54 else { 55 printf("%d\n", ans); 56 } 57 } 58 return 0; 59 }
问题 B: 喷水装置(二)(在c++上运行有错误,提交AC了)
标签:
原文地址:http://www.cnblogs.com/tong69/p/5798776.html