POJ-2398
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 4243 | Accepted: 2517 |
Description
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
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
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
/**
题意:给一个区域的左上和右上坐标,然后给出区域中的n条边,然后,给出m个玩具的坐标;
但是没有排序,要求比如说是有一个玩具的区域的个数
做法:计算几何
**/
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#define maxn 5000 + 10
using namespace std;
int n,m;
int mmap[maxn];
int mmpp[maxn];
const double eps = 1e-;
const double PI = acos(-1.0);
struct Point
{
double x;
double y;
Point(){}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator - (const Point &b) const
{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b) const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b) const
{
return x*b.x + y*b.y;
}
}point[maxn];
struct Line
{
Point s;
Point e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
}line[maxn];
bool cmp(Line a,Line b)
{
return a.s.x < b.s.x;
}
int mul(Point a,Point b,Point c)
{
return (b - a) ^(c - a);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int x1,y1,x2,y2;
while(~scanf("%d",&n))
{
if(n == ) break;
memset(mmap,,sizeof(mmap));
memset(mmpp,,sizeof(mmpp));
scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2);
int u,l;
for(int i=;i<n;i++)
{
scanf("%d %d",&u,&l);
line[i] = Line(Point(u,y1),Point(l,y2));
}
line[n] = Line(Point(x2,y1),Point(x2,y2));
sort(line,line+n+,cmp);
int x,y;
for(int i=;i<m;i++)
{
scanf("%d %d",&x,&y);
Point pp = Point(x,y);
int left = ;
int right = n;
int tmp = ;
while(left <= right)
{
int mid = (left + right) >>;
if(mul(pp,line[mid].s,line[mid].e)<)
{
tmp = mid;
right = mid-;
}
else left = mid+;
}
mmap[tmp] ++;
}
int mmax = ;
for(int i=;i<=n;i++)
{
mmpp[i] = ;
}
for(int i=;i<=n;i++)
{
if(mmap[i]>) mmpp[mmap[i]] ++;
}
printf("Box\n");
for(int i=;i<=n;i++)
{
if(mmpp[i]>) printf("%d: %d\n",i,mmpp[i]);
}
}
return ;
}
POJ-2398的更多相关文章
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage
题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
- poj 2398 Toy Storage(计算几何)
题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...
- poj 2398 (叉积+二分)
http://poj.org/problem?id=2398 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]
题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad ...
- POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3146 Accepted: 1798 Descr ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- POJ 2398 Toy Storage
这道题和POJ 2318几乎是一样的. 区别就是输入中坐标不给排序了,=_=|| 输出变成了,有多少个区域中有t个点. #include <cstdio> #include <cma ...
随机推荐
- BZOJ1491 洛谷2047 NOI2007 社交网络
Description: 在社交网络(social network)的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题.在一个社交圈子里有n个人,人与人之间有不同程度的关系.我 们 ...
- 【图论】Floyd消圈算法
毫无卵用的百度百科 Definition&Solution 对于一个给定的链表,如何判定它是否存在环以及环的长度问题,可以使用Floyd消圈算法求出. 从某种意义上来讲,带环的链表在本质上是一 ...
- Codeforces Round #514 (Div. 2):D. Nature Reserve(二分+数学)
D. Nature Reserve 题目链接:https://codeforces.com/contest/1059/problem/D 题意: 在二维坐标平面上给出n个数的点,现在要求一个圆,能够容 ...
- [ldap]ldap相关问题
背景: ldap数据库要同步,按照如下操作步骤: 1.导出: 使用slapcat,slapcat直接对数据库操作, slapcat 2.将所需的条目取出,生成文件in.ldif 3.在目标机器上导入: ...
- Python学习笔记(Django篇)——3、创建第一个数据库模型
Django里面集成了SQLite的数据库,对于初期研究来说,可以用这个学习. 第一步,创建数据库就涉及到建表等一系列的工作,在此之前,要先在cmd执行一个命令: python manage.py ...
- bug级别分类
bug级别分类 2014-10-20 10:02 6403人阅读 评论(0) 收藏 举报 分类: SQA(17) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 由 ...
- Linux和windows下检查jsp后门文件的方法
Linux下: find . -name "*.jsp" | xargs egrep -liw "createNewFile| File\(| File |applica ...
- div 超出高度滚动条,超出宽度点点点
超出高度滚动条 style="width:230px; height: 180px; overflow: auto;" 超出宽度点点点 style="width: 220 ...
- 第一章:读取文件一行IO::File
#!c:\\perl\\bin\\perl.exe use IO::File; #读取一行 my $fd = IO::File->new('perl.txt'); my $one_line = ...
- mysql执行load_fle返回NULL的解决方法
mysql 版本: 5.7.18 问题: 在执行mysql 函数load_file时,该函数将加载指定文件的内容,存储至相应字段.如: SELECT LOAD_FILE("D:\aa.txt ...