标签:
Sample Input
8 20 2
5 3
4 1
1 2
7 2
10 2
13 3
16 2
19 4
3 10 1
3 5
9 3
6 1
3 10 1
5 3
1 1
9 1
Sample Output
6
2
-1
这题和我之前写的那道区域覆盖题基本是相同的。
AC代码:#include <stdio.h>
#include <string.h> #include <math.h> #include <algorithm> using namespace std; int n,f;; double l, w; double s, t; struct qujian { double start; double end; } ; qujian a[10005]; int cmp(qujian a,qujian b) { return a.end > b.end; } int main() { while (~scanf("%d%lf%lf", &n, &l, &w))
while (scanf("%d%lf%lf", &n, &l, &w)==3)
//在此,要加==3或者为~scanf(),不然会超时 { double start=0; f= 0; for (int i = 0; i < n; i ++) { scanf("%lf%lf", &s, &t); a[i].start = v - sqrt(r * r - w * w / 4); //开平方必须用double型,这里的式子是勾股定理 a[i].end = v + sqrt(r * r - w * w / 4); } sort(a,a+ n, cmp); while (start<l) { int i; for (i = 0; i < n; i ++) { if (a[i].start <=start&& a[i].end>start) { start=a[i].end; f++; break; } } if(i==n) break; } if (start<l) printf("-1\n"); else printf("%d\n",f); } return 0; }
uva 10382 - Watering Grass(区域覆盖问题)
标签:
原文地址:http://www.cnblogs.com/hfc-xx/p/4705895.html