题目链接 Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4104   Accepted: 2433 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 rectangula…
Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 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…
题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段有序且不相交) 解答: 因为线段是有序给出,所以不用排序,判断某个点在哪个区域,采用二分法,将某个点和线段的叉积来判断这个点是在线的左边或者右边,根据这个来二分找出区域. 这是第一道计算几何的题目,怎么说呢,对于二分的边界问题还有点搞不清楚,这次是对线段二分,感觉二分真的很有用处. 开阔思维!!!具…
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域有多少个玩具 分析:从左往右.直到推断玩具是否在线段的逆时针方向为止.这个就须要用到叉积,当然能够用二分查找优化. 叉积:已知向量a(x1,y1),向量b(x2,y2),axb=x1*y2-x2*y1, 若axb>0,a在b的逆时针方向,若axb<0,则a在b的顺时针方向 注:每组数据后要多空一行…
题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有\(t​\)个玩具的隔间数(对\(t>0​\)都要输出). 题目分析:涉及到计算几何的知识是求点在线的哪一侧.可以利用叉积来做.取点\(A\)到隔板的上端点\(B\)的向量\(\vec{AB}\)叉乘点\(A\)到隔板的下端点\(C\)的向量\(\vec{AC}\).叉积的公式\(\vec a\ti…
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而2318要求输出的是有 i 个玩具的区间有几个. 思路 : 两个题基本差不多,只不过2398排一下序,然后再找个数组标记一下就行. 这个题我一开始没想到用二分,判断了点在四边形内但是没写下去,然后看了网上的二分区间,利用叉积判断点在左边还是右边. 2318代码: #include <stdio.h> #…
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由abcd围成的四边形区域内,那么向量ab, bc, cd, da和点的关系就是,点都在他们的同一侧,我是按照逆时针来算的,所以只需要判断叉积是否小于0就行了.还有一个问题就是这个题要求时间是2s,所以直接找,不用二分也能过,不过超过1s了,最好还是二分来做,二分时间170ms,二分的时候要把最左边的一条…
二分点所在区域,叉积判断左右 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdio> using namespace std; const int N=1005; int T,n,m,x1,y1,x2,y2,ans[N],cnt[N]; struct dian { double x,y; dian(double X=0,d…
题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化.用到了叉积 /************************************************ * Author :Running_Time * Created Time :2015/10/23 星期五 11:38:18 * File Name :POJ_2318.cpp ****…
Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 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…
Toy Storage Time Limit: 1000MS Memory Limit: 65536K 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…
Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4588   Accepted: 2718 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…
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…
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…
题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数. 题解:通过斜率判断一个点是否在两条线段之间. /** 通过斜率比较点是否在两线段之间 */ #include"iostream" #include"cstdio" #include"algorithm" #include"cstring" using namespace std; const int N=100…
题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K 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…
这道题和POJ 2318几乎是一样的. 区别就是输入中坐标不给排序了,=_=|| 输出变成了,有多少个区域中有t个点. #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; struct Point { int x, y; Point(, ):x(x), y(y) {} }; typedef Point Vector; P…
计算几何终于开坑了... 叉积+二分. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 5050 using namespace std; struct point { int x,y; point (int x,int y):x(x),y(y) {} point () {} friend point operator-(point…
Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6534   Accepted: 3905 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…
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in…
题目连接: http://poj.org/problem?id=2318     http://poj.org/problem?id=2398 两题类似的题目,2398是2318的升级版. 题目大概是说,有一个矩形的柜子,中间有一些隔板.告诉你每个隔板的坐标,还有一些玩具的坐标,统计玩具在哪个格子里. 这题的思路很简单,如果玩具在某个隔板的左边和右边叉乘的正负是不同的.如图: 图中点P在线段CD的左边,则向量PC和向量PD叉乘结果小于0.反之P在AB的左边,向量PA叉乘PB大于0. 因此利用这个…
题意:给定n(<=5000)条线段,把一个矩阵分成了n+1分了,有m个玩具,放在为位置是(x,y).现在要问第几个位置上有多少个玩具. 思路:叉积,线段p1p2,记玩具为p0,那么如果(p1p2 ^ p1p0) (记得不能搞反顺序,不同的),如果他们的叉积是小于0,那么就是在线段的左边,否则右边.所以,可以用二分找,如果在mid的左边,end=mid-1 否则begin=mid+1.结束的begin,就是第一条在点右边的线段 #include <cstdio> #include <…
http://poj.org/problem?id=2398 Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3831   Accepted: 2256 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. T…
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…
// 题意:问你每个区域有多少个点 // 思路:数据小可以直接暴力 // 也可以二分区间 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stdlib.h> #include <cmat…
poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区域,然后分别用0到n表示,m代表玩具的个数,(x1,y1)代表盒子的左上顶点坐标,(x2,y2)代表盒子的右下顶点坐标,接下来的n行,每行都有两个数a,b,(a,y1),(b,y2)分别代表卡片的两个顶点位置,接下来的m行每行两个数从c,d,(c,d),代表玩具放置的坐标,最后让你输出当区域内玩具的…
Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8862   Accepted: 3262 Description Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find…
TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13120   Accepted: 6334 Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away w…
题目大意:给你一个矩形的左上角和右下角的坐标,然后这个矩形有 N 个隔板分割成 N+1 个区域,下面有 M 组坐标,求出来每个区域包含的坐标数.   分析:做的第一道计算几何题目....使用叉积判断方向,然后使用二分查询找到点所在的区域.   代码如下: ==========================================================================================================================…
题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular bo…