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. Github & DMCA Takedown Policy

    Github & DMCA Takedown Policy Digital Millennium Copyright Act 数字千年版权法案 https://help.github.com/ ...

  2. Div+Css中transparent制作奥运五环

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. BZOJ4563 HAOI2016放棋子(高精度)

    没看清题还以为是要求数最大匹配数量……注意到任意障碍不在同一行同一列,且恰好有n个障碍,不妨通过交换列使得第i行第i列均有障碍.那么就是个错排了.居然wa了一发简直没救. #include<io ...

  4. 【转】如何解决每次打开office2010都会出现正在配置以及使用KMS

    转自:http://jingyan.baidu.com/article/90895e0fb1525964ec6b0bb5.html 一.使用mini-KMS_Activator_v1.2_Office ...

  5. [洛谷P2210]Haywire

    题目大意:有$n(n\leqslant12)$个数,每个数和其他三个数连边,求一个排列,使得边的长度最小 题解:状压$DP$,$f_{i,j}$表示当前确定的数状态为$i$,有$j$条边起点被确定终点 ...

  6. HDU 2844 二进制优化的多重背包

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. [ZJOI2005]午餐 (DP)

    [ZJOI2005]午餐 题目描述 上午的训练结束了,THU ACM小组集体去吃午餐,他们一行N人来到了著名的十食堂.这里有两个打饭的窗口,每个窗口同一时刻只能给一个人打饭.由于每个人的口味(以及胃口 ...

  8. codeforces 719C. Efim and Strange Grade

    C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. jquery的ajax实现方式

    在JQuery中,AJAX有三种实现方式:$.ajax() , $.post , $.get(). 首先我们看$.get(): .代码如下: $.get("test.jsp", { ...

  10. count(1)与count(*)

    http://www.cnblogs.com/sueris/p/6650301.html 结论:实际项目中count(1)用到多 记得很早以前就有人跟我说过,在使用count的时候要用count(1) ...