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 ...
随机推荐
- SpringBoot 入门学习(HelloWord)
前置知识 1.会利用 maven 构建项目 2.了解 Spring 注解 3.了解 RESTful API 的基本理论 4.SpringBoot 是 SpringMVC 的升级版,但两者没有必然的联系 ...
- java 利用反射完成自定义注解
元注解: 元注解的作用就是负责注解其他注解.Java5.0定义了4个标准的meta-annotation类型,它们被用来提供对其它 annotation类型作说明.Java5.0定义的元注解: 1.@ ...
- JavaScript选择打开手机网站还是电脑网站
现在手机网站越来越普遍,类似京东.淘宝.新浪等等大家都推出了wap版,一种简单的方法判断,JavaScript选择打开手机网站还是电脑网站,如果是手机网站就让网页跳转到手机网址.如果是电脑网站,打开电 ...
- Sublime Text 2创建可复用的代码片段
对于前端工程师来讲,写一个html页面的基本结构是体力活,每次去拷贝一个也麻烦,sublime text 2 提供了一个很好的复用代码片段.下面介绍一下创建一个html5的代码片段的过程.在菜单上点击 ...
- HDU 6201 transaction transaction transaction(拆点最长路)
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- [洛谷P1879][USACO06NOV]玉米田Corn Fields
题目大意:有一个$n\times m$的矩阵,$(1 \leq m \leq 12; 1 \leq n \leq 12)$,想在其中的一些格子中种草,一些格子不能种草,且两块草地不相邻.问有多少种种植 ...
- 图解WinXP局域网共享设置步骤
原文链接地址:http://blog.csdn.net/jackinzhou/article/details/8468208 第一章:共享的前提工作 1.更改不同的计算机名,设置相同的工作组! 2.我 ...
- BZOJ 3545 / 洛谷 P4197 Peaks 解题报告
P4197 Peaks 题目描述 在\(\text{Bytemountains}\)有\(N\)座山峰,每座山峰有他的高度\(h_i\).有些山峰之间有双向道路相连,共\(M\)条路径,每条路径有一个 ...
- 强大的JQuery数组封装使用
JQuery对数组的处理非常便捷并且功能强大齐全,一步到位的封装了很多原生js数组不能企及的功能.下面来看看JQuery数组的强大之处在哪. $.each(array, [callback]) 遍历 ...
- css3中-moz、-ms、-webkit分别代表的意思
这三个分别是目前流行的三种浏览器的私有属性 -moz代表firefox浏览器私有属性 -ms代表ie浏览器私有属性(360浏览器是ie内核) -webkit代表safari.chrome私有属性 -o ...