标签:des style blog http color os io strong
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 10281 | Accepted: 4924 |
Description
Input
Output
Sample Input
5 6 0 10 60 0 3 1 4 3 6 8 10 10 15 30 1 5 2 1 2 8 5 5 40 10 7 9 4 10 0 10 100 0 20 20 40 40 60 60 80 80 5 10 15 10 25 10 35 10 45 10 55 10 65 10 75 10 85 10 95 10 0
Sample Output
0: 2 1: 1 2: 1 3: 1 4: 0 5: 1 0: 2 1: 2 2: 2 3: 2 4: 2
Hint
1 #include <cstdio> 2 #include <cstring> 3 4 const int LEN = 5050; 5 6 struct Point //点的结构体 7 { 8 int x; 9 int y; 10 }; 11 12 struct Line //线段的结构体 13 { 14 Point a; 15 Point b; 16 }line[LEN]; 17 18 int ans[LEN]; 19 20 int judge(Line tline, Point p3) //运用叉积的性质判断点在线段的左边还是右边 21 { 22 Point t1, t2; 23 t1.x = p3.x - tline.b.x; 24 t1.y = p3.y - tline.b.y; 25 t2.x = tline.a.x - tline.b.x; 26 t2.y = tline.a.y - tline.b.y; 27 return t1.x * t2.y - t1.y * t2.x; 28 } 29 30 int divide(int l, int r, Point toy) //二分查找 31 { 32 int mid = (l + r) / 2; 33 if (mid == l) 34 return l; 35 if (judge(line[mid], toy) < 0) 36 return divide(l, mid, toy); 37 else 38 return divide(mid, r, toy); 39 } 40 41 int main() 42 { 43 int n, m, x1, y1, x2, y2; 44 //freopen("in.txt", "r", stdin); 45 while(scanf("%d", &n) != EOF && n){ 46 scanf("%d %d %d %d %d", &m, &x1, &y1, &x2, &y2); 47 memset(ans, 0, sizeof(ans)); 48 for(int i = 1; i <= n; i++){ 49 int up, low; 50 scanf("%d %d", &up, &low); 51 line[i].a.x = up; 52 line[i].a.y = y1; 53 line[i].b.x = low; 54 line[i].b.y = y2; 55 } 56 n++; 57 line[0].a.x = line[0].b.x = x1; 58 line[0].b.y = line[n].b.y = y2; 59 line[0].a.y = line[n].a.y = y1; 60 line[n].a.x = line[n].b.x = x2; 61 for(int i = 0; i < m; i++){ 62 Point toy; 63 scanf("%d %d", &toy.x, &toy.y); 64 ans[divide(0, n, toy)]++; 65 } 66 for(int i = 0; i < n; i++){ 67 printf("%d: %d\n", i, ans[i]); 68 } 69 printf("\n"); 70 } 71 return 0; 72 }
【POJ】2318 TOYS ——计算几何+二分,布布扣,bubuko.com
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/kevince/p/3888721.html