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 ...
随机推荐
- [ssh]ssh系列之一
1.使用ssh建立sock代理 ssh -D 7070 -f -N user@host -D -f 后台执行 -N 不登陆shell执行
- 【Android】Android之Copy and Paste
Android为复制粘贴提供了一个强大的基于剪切板的框架,它支持简单和复杂的数据类型,包括纯文本,复杂的数据结构,二进制流,甚至app资源文件.简单的文本数据直接存储在剪切板中,而复杂的数据则存储的是 ...
- git概论
感谢:http://www.cnblogs.com/atyou/archive/2013/03/11/2953579.html git,一个非常强大的版本管理工具.Github则是一个基于Git的日益 ...
- 数据结构&字符串:可持久化字典树
利用可持久化Trie树实现范围内取值异或最大值 如果标题没有表达清楚意思,可以看这里的题干: 然后根据异或的性质,异或一个数两次相当于没有异或,那么我们可以维护一个异或前缀和 有了异或前缀和之后我们就 ...
- iOS 网络请求--- 配置info.plist文件
一.配置info.plist <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitra ...
- 安装显卡后蓝屏0x00000116解决办法
1. 亲自遇到蓝屏的问题. 2. 进入安全模式后重装系统,成功. 3. 安装驱动,软件没毛病.安装显卡驱动后,蓝屏. 4. 查看蓝屏错误代码0x00000116, 百度后查看到是显卡驱动的问题. 5. ...
- bzoj 1577: [Usaco2009 Feb]庙会捷运Fair Shuttle——小根堆+大根堆+贪心
Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i群牛一共有Mi(1& ...
- 【洛谷 P4735】 最大异或和 (可持久化Trie)
题目链接 维护整个数列的异或前缀和和\(s\),然后每次就是要求\(s[N]\text{^}x\text{^}s[k],l-1<=k<=r-1\)的最大值 如果没有\(l\)的限制,那么直 ...
- HDU 1312 Red and Black (深搜)
题目链接 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore ...
- elementui raido 单选框 循环渲染加:key
<el-radio-group v-model="adminRole"> <el-radio v-for="item in adminRoles&quo ...