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. windows下 eclipse搭建spark java编译环境

    环境: win10 jdk1.8 之前有在虚拟机或者集群上安装spark安装包的,解压到你想要放spark的本地目录下,比如我的目录就是D:\Hadoop\spark-1.6.0-bin-hadoop ...

  2. 推荐一个好的Redis GUI 客户端工具

    推荐一个好的Redis GUI 客户端工具 Redis Desktop Manager  

  3. EF to linq 左连接

    如果连接的数据不存在用 null 表示,则可以左连接查询,但是如果数据类型为 int 则会出错. var ng = (from g in _db.NET_NEWS_GROUP join z in _d ...

  4. iMuseum

    iMuseum 每日环球展览 iMuseum https://itunes.apple.com/cn/app/%E6%AF%8F%E6%97%A5%E7%8E%AF%E7%90%83%E5%B1%95 ...

  5. 【bzoj4724】[POI2017]Podzielno 二分

    题目描述 B进制数,每个数字i(i=0,1,...,B-1)有a[i]个.你要用这些数字组成一个最大的B进制数X(不能有前导零,不需要用完所有数字),使得X是B-1的倍数.q次询问,每次询问X在B进制 ...

  6. 奇异值分解(SVD)小结

    SVD(奇异值分解)真的是一个神奇的东西,这里就写个小结. 其实原理并不是那么难理解. 它在数据去噪方面和降维上有特殊作用,也与PCA有很大的联系. 首先我们先回顾一下 EVD,特征值分解,可以对SV ...

  7. hihocoder 1323 回文字符串(字符串+dp)

    题解: 比较水的题目 dp[i][j]表示[i...j]最少改变几次变成回文字符串 那么有三种转移 dp[i][j] = dp[i+1][j-1] + s[i] != s[j] dp[i][j] = ...

  8. js金额转大写数字

    //金额转大写数字 const intToChinese = money => { //汉字的数字 let cnNums = new Array('零', '壹', '贰', '叁', '肆', ...

  9. [poj 3261]后缀数组+滑窗最小值

    题目链接:http://poj.org/problem?id=3261 这个是可以交叉的重复串,所以用height就可以了,但是题目说让重复k次以上,也就是直接做一个k-1长度的滑窗最小值,从这些最小 ...

  10. css和javascript中图片路径的不同

    之前在写前端代码时,在图片路径的设置那里经常会遇到一个问题.比方说,我 (1)在根目录下面新建了个"images"文夹,里面放了张图片top.gif (2)在根目录下另外新建了两个 ...