随笔分类 - 计算几何
摘要:题意:判断圆是否与矩形相交。分析:分别判断矩形的四条边是否与圆相交即可,即转化为判断线段与圆是否相交。#include <stdio.h>#include <string.h>#include <math.h>const double eps = 1e-8;double rx[4],ry[4];double cx,cy,r;double mul(double x1,double y1,double x2,double y2){ return x1*y2-x2*y1;}double dis(double x1,double y1,double x2,doubl
阅读全文
摘要:题意: 知道了正多边形内部一个点和其他所有点的距离,假如此正多边形存在则输出此正多边形边长,否则输出 impossible。分析:二分多边形的边长,对于每一个边长求出对应的内角和,假如内角和小与 360,则此边长比实际值要小,否则大于实际边长。#include<stdio.h>#include<string.h>#include<math.h>const double eps=1e-6;const double P=acos(-1.0);double d[105];double ab(double a){ return a>0?a:-a; }int n
阅读全文
摘要:题意:知道了n 个房子的坐标,和m 个金矿的坐标,问可以选出多少个三个房子,使得这三个房子内部的金矿数为奇数。分析: 直接暴力枚举的时间复杂度是o(n^4),可以先进行预处理 定义数组dp[i][j] 表示在房子 i 和放在 j 之间连线的上方的金矿数量, 则 房子 i,j, k, 内部的金矿数为 sum = dp[i][j]-dp[i][k]-dp[j][k]#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#define clr(x)memset(x,0,
阅读全文
摘要:题意: 求多边形重心。分析: 直接利用公式。#include<stdio.h>#include<string.h>#include<math.h>struct node{ double x,y;}q[1000005],cen;double mul(node a,node b,node c){ return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}int main(){ double s,a; int t,n,i; scanf("%d",&t); while(t--) { scanf(&qu
阅读全文
摘要:题意: 给出一个有N个顶点的多边形,问该多边形内是否存在一点满足在该点可以看到多边形内部任意一个位置。分析: 求多边形内核。#include<stdio.h>#include<string.h>#include<math.h>#define eps 1e-8#define maxn 105struct point{ double x,y;}p[maxn],q[maxn],s[maxn];int n,size,si;void init(){ int i; for(i=1;i<=n;i++) p[i]=s[i]; p[n+1]=p[1]; p[0]=p[.
阅读全文
摘要:题意: 给出 N 只鱼的坐标,问用半径为 1 的渔网做多可以捕到多少鱼。分析: 以每条鱼为圆心,作半径为1 的圆,枚举两两圆的交点,比较以每个交点为圆心半径 1 的渔网最多捕获的鱼数。#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>const double eps=1e-6;struct node{ double x,y;}q[305];double dis(node a,node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.
阅读全文
摘要:题意: 给出 N 个矩形,可以相互覆盖,求所有矩形合在一起的轮廓总长度。分析:先对所有矩形按左下角的Y 坐标排序,让矩形的所有点向 X 轴投影,记录所有的投影的X值,对X 排序,分段累加X 坐标差值; ① 如果 s[i].y1>up 说明两个矩形没有交集,即新的矩形没有被前一个矩形覆盖到 ,res+=2*(right[i]-right[i-1]) 累加新的横边覆盖值。 ② 如果 s[i].y2>up 说明新的矩形下边界在该 相邻 X 的区间被覆盖,所以只要更新给 区间的上边界 UP=s[i].y2 然后对矩形按左下角的X 坐标排序,让矩形向y轴作投影,最后按照类似的方法求出 所有竖
阅读全文
摘要:题意: 有N 个点,且这些点都在整数坐标上,找出一个点使得所有点到这个点的曼哈顿距离和最小。分析:可以以每个点为中心,把平面分别按 位于该点上方, 位于该点下方, 位于该点左方, 位于该点右方, 可以先对 X 排序, 记点的左方所有点到该点的 X 坐标距离差之和为 LX 记点的右方所有点到该点的 X 坐标距离差之和为 RX 求出第一个点的 LX,RX 后,后面的点可依次有前一个点推出 即 LX2=LX+i*dxRX2=RX-(n-i)*dx每个点上方的 Y 距离差之和 SY,和下方的 XY 求法同上, 最后枚举每个点的 LX+RX+XY+SY找出最大值即可。#include<stdio.
阅读全文
摘要:题意: 有 n 个萝莉,和 m 个怪叔叔,已知他们的坐标,且任意三个人不共线,要求从萝莉中任选三个人出来,且三个人 组成的三角形中不能包含怪叔叔,共有多少种取法。分析: 将萝莉的坐标按横坐标排序,用 f[i][j] 表示萝莉 i 到萝莉 j 的横坐标范围内,位于萝莉 i ,j上方的 怪叔叔数量,对于横坐标依次增加的 萝莉 i,j,k ,如果有 f[i][j]+f[j][k]=f[i][k], 则 萝莉 i,j,k 组成的三角形内不含有怪叔叔(画图能够看出)。 时间复杂度为 O(N^3)。View Code #include<stdio.h>#include<string.h&
阅读全文
摘要:题意: 给一个起点和一个终点,然后给出 N 个互不相交的栅栏,问从起点到终点如果不穿过栅栏(可以接触)最少需要走多 远的距离。分析: 如果两个点所在线段,没有其它线段与之相交,则可以在两点之间连一条线段,最后只要求出起点到终点的最短距离即可, 时间复杂度O(N^3)CODE :View Code #include<stdio.h>#include<string.h>#include<math.h>double min(double a,double b){ return a<b?a:b; }double max(double a,double b){
阅读全文
摘要:题意: 有一个 n 个点组成的凸多边形, 和 m 个点,问 M 个点是否全部严格在多边形内部。转大牛分析:考虑将一个凸包划分为N个三角区域于是可知对于某个点,如果不在这些三角区域内,那么必然不在凸包内否则,可以通过二分位置,得到点所在的区间之后只需要判断点 是否在区间所对应的原凸包的边的左边即可(逆时针给出凸包点顺序)假设我们查询绿色的点是否在凸包内,我们首先二分得到了它所在的区间,然后判断它和绿色的向量的关系,蓝色和紫色的点类似,蓝色的点在边界上,紫色的点在边界右边因此一个查询在O(logN)内解决 code:View Code #include<stdio.h>#include
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<stdlib.h>struct node{ long long x,y;}p[50003],a[50003],t1;long long mul(node p1,node p2,node p3){ return (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x);}long long dis(node a,node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.
阅读全文
摘要:DescriptionThe most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y1999 and called it M11. It has only one eye on the left side of its head and just three feet all on the right side of its body and suffers from th
阅读全文
摘要:DescriptionTigers are enclosed in wire-net fencing at zoo.If they get out of the fencing, they may attack people.We use some lines to present the fencing as the picture following:Your task is to judge if a tiger in the fencing or not.In picture 1 the tiger is in the fencing.Note that enclosed fencin
阅读全文
摘要:Description一个封闭的多边形定义是被有限个线段包围。线段的相交点称作多边形的顶点,当你从多边形的一个顶点沿着线段行走时,最终你会回到出发点。凸多边形(convex)想必大家已经很熟悉了,下图给出了凸多边形和非凸多边形实例。这里讨论的是在平面坐标的封闭凸多边形,多变形的顶点一个顶点在原点(x=0,y=0).图2显示的那样。这样的图形有两种性质。第一种性质是多边形的顶点会在平面上少于等于三个象限,就如图二那样,第二向县里面没有多边形的点(x<0,y>0)。为了解释第二种性质,假设你沿着多边形旅行,从原点(0,0)出发遍历每个顶点一次,当你遍历到除原点(0,0)时候,从这一点画
阅读全文
摘要:DescriptionArcheologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine that the lower floor of the pyramid is constructed from a series of straightline walls, which intersect to f
阅读全文
摘要:DescriptionStan 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 the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he
阅读全文
摘要:DescriptionCalculate 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 box to put his toys in, but John is rebellious and obeys his parents by s
阅读全文
摘要:Problem DescriptionMany geometry(几何)problems were designed in the ACM/ICPC. And now, I also prepare a geometry problem for this final exam. According to the experience of many ACMers, geometry problems are always much trouble, but this problem is very easy, after all we are now attending an exam, no
阅读全文


浙公网安备 33010602011771号