poj 2398(叉积判断点在线段的哪一侧)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 5016 | Accepted: 2978 |
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 比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(叉积判断点在线段的哪一侧)的更多相关文章
- poj 2318(叉积判断点在线段的哪一侧)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13120 Accepted: 6334 Description ...
- POJ 2318 TOYS 利用叉积判断点在线段的那一侧
题意:给定n(<=5000)条线段,把一个矩阵分成了n+1分了,有m个玩具,放在为位置是(x,y).现在要问第几个位置上有多少个玩具. 思路:叉积,线段p1p2,记玩具为p0,那么如果(p1p2 ...
- POJ 3304 Segments (判断直线与线段相交)
题目链接:POJ 3304 Problem Description Given n segments in the two dimensional space, write a program, wh ...
- POJ 3304 Segments 判断直线和线段相交
POJ 3304 Segments 题意:给定n(n<=100)条线段,问你是否存在这样的一条直线,使得所有线段投影下去后,至少都有一个交点. 思路:对于投影在所求直线上面的相交阴影,我们可以 ...
- poj3304(叉积判断直线和线段相交)
题目链接:https://vjudge.net/problem/POJ-3304 题意:求是否能找到一条直线,使得n条线段在该直线的投影有公共点. 思路: 如果存在这样的直线,那么在公共投影点作直线的 ...
- POJ 2318 叉积判断点与直线位置
TOYS Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom ...
- POJ 2398 map /// 判断点与直线的位置关系
题目大意: poj2318改个输出 输出 a: b 即有a个玩具的格子有b个 可以先看下poj2318的报告 用map就很方便 #include <cstdio> #include < ...
- [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)
题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...
- POJ 2318 TOYS (计算几何,叉积判断)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8661 Accepted: 4114 Description ...
随机推荐
- javascript中的大括号和中括号
文章:javascript中{},[]中括号,大括号的含义和使用
- C#故事
C# 在腾讯的发展 <先定个小目标, 使用C# 开发的千万级应用> Xamarin 携程使用.Net技术 分布式高并发redis MQ dubbo kafka zookeeper
- HDU 1028 整数拆分问题 Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- Android Studio的初体验
在机缘巧合之下遇到了安卓开发,接触了Android Studio开始了漫长的改bug的道路,以下为简易版心酸历程 首先我需要成功安装Android Studio,由于我过于叛逆以及为了避免出错于是从一 ...
- HDU 1798 Tell me the area
http://acm.hdu.edu.cn/showproblem.php?pid=1798 Problem Description There are two circles in the ...
- linux启动和关闭防火墙命令
在此说一下关于启动和关闭防火墙的命令:1) 重启后生效开启: chkconfig iptables on关闭: chkconfig iptables off2) 即时生效,重启后失效开启: servi ...
- Div+Css中transparent制作奥运五环
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Codeforces Round #519 by Botan Investments翻车记
A:枚举答案即可.注意答案最大可达201,因为这个wa了一发瞬间爆炸. #include<iostream> #include<cstdio> #include<cmat ...
- [Leetcode] Copy list with random pointer 对带有任意指针的链表深度拷贝
A linked list is given such that each node contains an additional random pointer which could point t ...
- [Leetcode] set matrix zeroes 矩阵置零
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...