Toy Storage
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5016   Accepted: 2978

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 比poj 2318多了个排序。暴力解16MS
#include <iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
#include <algorithm> using namespace std;
const int N = ;
struct Point
{
int x,y;
} p[N],q[N];
struct Line{
Point a,b;
}line[N];
int n,m,x1,y11,x2,y2; bool used[N];
int cnt[N]; ///判断某区域的点数量
int area[N];
int mult(Point a,Point b,Point c){
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
int cmp(Line l1,Line l2){
if (min(l1.a.x, l1.b.x)==min(l2.a.x, l1.b.x))
return max(l1.a.x, l1.b.x) < max(l2.a.x, l1.b.x);
return min(l1.a.x, l1.b.x) < min(l2.a.x, l1.b.x);
}
int main()
{
while(scanf("%d",&n)!=EOF,n)
{ scanf("%d%d%d%d%d",&m,&x1,&y11,&x2,&y2);
memset(used,false,sizeof(used));
memset(cnt,,sizeof(cnt));
memset(area,,sizeof(area));
int k=;
for(int i=;i<=n;i++){
scanf("%d%d",&line[i].a.x,&line[i].b.x);
line[i].a.y=y11,line[i].b.y=y2;
}
sort(line+,line+n+,cmp);
/*for(int i=1;i<=n;i++){
printf("%d %d %d %d\n",line[i].a.x,line[i].a.y,line[i].b.x,line[i].b.y);
}*/
for(int i=;i<m;i++){
scanf("%d%d",&q[i].x,&q[i].y);
}
int sum=;
for(int i=;i<=n;i++){
for(int j=;j<m;j++){
if(mult(line[i].a,q[j],line[i].b)>&&!used[j]){
cnt[i-]++;
used[j]=true;
}
}
sum+=cnt[i-];
}
cnt[n] = m-sum; for(int i=;i<=n;i++){
if(cnt[i]){
area[cnt[i]]++;
}
}printf("Box\n");
for(int i=;i<=m;i++){
if(area[i]){
printf("%d: %d\n",i,area[i]);
}
}
}
return ;
}

poj 2398(叉积判断点在线段的哪一侧)的更多相关文章

  1. poj 2318(叉积判断点在线段的哪一侧)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13120   Accepted: 6334 Description ...

  2. POJ 2318 TOYS 利用叉积判断点在线段的那一侧

    题意:给定n(<=5000)条线段,把一个矩阵分成了n+1分了,有m个玩具,放在为位置是(x,y).现在要问第几个位置上有多少个玩具. 思路:叉积,线段p1p2,记玩具为p0,那么如果(p1p2 ...

  3. POJ 3304 Segments (判断直线与线段相交)

    题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...

  4. POJ 3304 Segments 判断直线和线段相交

    POJ 3304  Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...

  5. poj3304(叉积判断直线和线段相交)

    题目链接:https://vjudge.net/problem/POJ-3304 题意:求是否能找到一条直线,使得n条线段在该直线的投影有公共点. 思路: 如果存在这样的直线,那么在公共投影点作直线的 ...

  6. POJ 2318 叉积判断点与直线位置

    TOYS   Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom ...

  7. POJ 2398 map /// 判断点与直线的位置关系

    题目大意: poj2318改个输出 输出 a: b 即有a个玩具的格子有b个 可以先看下poj2318的报告 用map就很方便 #include <cstdio> #include < ...

  8. [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)

    题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...

  9. POJ 2318 TOYS (计算几何,叉积判断)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8661   Accepted: 4114 Description ...

随机推荐

  1. beta版本冲刺四

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员:恺琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示组 ...

  2. java的命名空间

    这个package  me.gacl.websocket相当于.net中的namespace命名空间. import  相当于.net中的using,引用命名空间:

  3. lintcode-117-跳跃游戏 II

    117-跳跃游戏 II 给出一个非负整数数组,你最初定位在数组的第一个位置. 数组中的每个元素代表你在那个位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 样例 给出数组 ...

  4. windows apache启动报错

    Windows启动Apache时报错 he requested operation has failed 有可能80端口被占或者项目路径不存在等 首先找到问题原因 cmd--命令端--切换到apach ...

  5. Topcoder SRM579 1000pts

    石头剪刀布QAQ 一看是个很油的概率dp 首先一看你很快能得出状态的表示F[i][r][p][s] 然后只要考虑r,p,s出现的次数来进行概率dp就好了 具体实现的时候细节很多(少) 如果预处理一下组 ...

  6. 【BZOJ 4605】崂山白花蛇草水 替罪羊树套线段树

    外层是借鉴了kd-tree的替罪羊里层是线段树,插入就是正常插入+拍扁重建,查询的时候,我们就像树状数组套线段树一样操作在替罪羊中找到的线段树根节点,但是对于在kd-tree查找过程中遇到的单点,我们 ...

  7. OpenJudge百炼-2747-数字方格-C语言-枚举

    描述:如上图,有3个方格,每个方格里面都有一个整数a1,a2,a3.已知0 <= a1, a2, a3 <= n,而且a1 + a2是2的倍数,a2 + a3是3的倍数, a1 + a2 ...

  8. 转:JVM Server与Client运行模式

    转自:http://blog.csdn.net/zhuyijian135757/article/details/38391785 JVM Server模式与client模式启动,最主要的差别在于:-S ...

  9. macos装多个python

    简介 Mac包管理工具brew: 安装方法:命令行输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Ho ...

  10. UOJ#80 二分图最大权匹配 [模板题]

    从前一个和谐的班级,有 nlnl 个是男生,有 nrnr 个是女生.编号分别为 1,…,nl1,…,nl 和 1,…,nr1,…,nr. 有若干个这样的条件:第 vv 个男生和第 uu 个女生愿意结为 ...