zoukankan      html  css  js  c++  java
  • POJ2398(KB13-B 计算几何)

    Toy Storage

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 5968   Accepted: 3573

    Description

    Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for Reza to find his favorite toys anymore. 
    Reza's parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top: 

    We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.

    Input

    The input consists of a number of cases. The first line consists of six integers n, m, x1, y1, x2, y2. The number of cardboards to form the partitions is n (0 < n <= 1000) and the number of toys is given in m (0 < m <= 1000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1, y1) and (x2, y2), respectively. The following n lines each consists of two integers Ui Li, indicating that the ends of the ith cardboard is at the coordinates (Ui, y1) and (Li, y2). You may assume that the cardboards do not intersect with each other. The next m lines each consists of two integers Xi Yi specifying where the ith toy has landed in the box. You may assume that no toy will land on a cardboard. 

    A line consisting of a single 0 terminates the input.

    Output

    For each box, first provide a header stating "Box" on a line of its own. After that, there will be one line of output per count (t > 0) of toys in a partition. The value t will be followed by a colon and a space, followed the number of partitions containing t toys. Output will be sorted in ascending order of t for each box.

    Sample Input

    4 10 0 10 100 0
    20 20
    80 80
    60 60
    40 40
    5 10
    15 10
    95 10
    25 10
    65 10
    75 10
    35 10
    45 10
    55 10
    85 10
    5 6 0 10 60 0
    4 3
    15 30
    3 1
    6 8
    10 10
    2 1
    2 8
    1 5
    5 5
    40 10
    7 9
    0
    

    Sample Output

    Box
    2: 5
    Box
    1: 4
    2: 1
    

    Source

     
    与A题相同,但是线没有排序,询问的是有t个玩具的区域有几个
     1 //2017-08-30
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 const int N = 5010;
    10 
    11 struct Point{
    12     int x, y;
    13     Point(){}
    14     Point(int _x, int _y):x(_x), y(_y){}
    15     //a-b 表示向量 ba
    16     Point operator- (const Point &b) const {
    17         return Point(x-b.x, y-b.y);
    18     }
    19     //向量叉积
    20     int operator* (const Point &b) const {
    21         return x*b.y - y*b.x;
    22     }
    23 }A, B;
    24 
    25 int ans[N], U[N], L[N], t[N];
    26 int n, m;
    27 
    28 bool check(int id, int x, int y){
    29     if(y == A.y)return x > U[id];
    30     if(y == B.y)return x > L[id];
    31     Point a(L[id], B.y);
    32     Point b(U[id], A.y);
    33     Point c(x, y);
    34     //令I = 向量ab 叉乘 向量 bc,若I为正,点c在向量ab的左侧(沿向量方向看);为负则在右侧
    35     return ((c-a)*(b-a)) > 0;
    36 }
    37 
    38 int get_position(int x, int y){
    39     int l = 0, r = n+1, mid, ans;
    40     while(l <= r){
    41         mid = (l+r)>>1;
    42         if(check(mid, x, y)){
    43             ans = mid;
    44             l = mid+1;
    45         }else r = mid-1;
    46     }
    47     return ans;
    48 }
    49 
    50 int main()
    51 {
    52     std::ios::sync_with_stdio(false);
    53     freopen("inputB.txt", "r", stdin);
    54     while(cin>>n && n){
    55         cin>>m>>A.x>>A.y>>B.x>>B.y;
    56         U[0] = L[0] = A.x;
    57         U[n+1] = L[n+1] = B.x;
    58         for(int i = 1; i <= n; i++)
    59           cin>>U[i]>>L[i];
    60         memset(ans, 0, sizeof(ans));
    61         sort(U, U+n+1);
    62         sort(L, L+n+1);
    63         int x, y;
    64         for(int i = 0; i < m; i++){
    65             cin>>x>>y;
    66             ans[get_position(x, y)]++;
    67         }
    68         memset(t, 0, sizeof(t));
    69         for(int i = 0; i <= n; i++)
    70           t[ans[i]]++;
    71         cout<<"Box"<<endl;
    72         for(int i = 1; i <= m; i++)
    73               if(t[i])
    74                   cout<<i<<": "<<t[i]<<endl;
    75     }
    76 
    77     return 0;
    78 }
  • 相关阅读:
    IA__gdk_drawable_get_size: assertion 'GDK_IS_DRAWABLE (drawable)' failed
    宿主机系统 Deepin 15.4,解决 Virtualbox 5.1 中 XP虚拟机无法使用 USB设备(如:U盘、罗技优联接收器等)的问题
    Deepin安装Virtualbox扩展包出现与gksu-run-helper通信失败的解决
    docker 学习资料收集
    从编程语言的角度看中医的【藏像】理论
    从程序员视角和编程语言角度看【中医】:一种生命健康编程语言
    使用微服务架构思想,设计部署API代理网关和OAuth2.0授权认证框架
    在Office应用中打开WPF窗体并且让子窗体显示在Office应用上
    彻底关闭Excle进程的几个方法
    70后.net老猿,尚能饭否?
  • 原文地址:https://www.cnblogs.com/Penn000/p/7453196.html
Copyright © 2011-2022 走看看