题目链接 Paint Tree 给你一棵n个点的树和n个直角坐标系上的点,现在要把树上的n个点映射到直角坐标系的n个点中,要求是除了在顶点处不能有线段的相交. 我们先选一个在直角坐标系中的最左下角的点,把根结点放到这个点中,然后对剩下的点进行极角排序,按逆时顺序一个个塞进来,类似地递归处理. 这样就满足了题意. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b…
C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line. Your task is to paint…
题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of…
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/C Description You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the mini…
分治.选最左上的点分给根.剩下的极角排序后递归 C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line…
E - Paint Tree You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line. Your task is to paint the given tree on a plane, using the given points as vertexes. That is, you should correspond each vertex of…
题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点所属于的区域 插入:平衡树log(n)内选出点所属于的区域, 与做一般凸包的时候类似,分别以该点向左右两边进行维护, 一直删除不满足凸包的点,直到所有点满足凸包为止. 水平序: 可以用2个平衡树分别维护上下2个半凸包,具体实现时可以把其中一个半凸包按y轴对称以后,那么2个半凸包的维护就是同一种方法,…
链接:https://codeforces.com/problemset/problem/1284/E 题意:平面上有n个点,问你存在多少组四个点围成的四边形 严格包围某个点P的情况.不存在三点共线. 思路:首先看数据范围是2500,可以做n^2的枚举,我们可以枚举两遍n.正面求解有些困难,反面求解可以考虑有多少组子集不满足题目要求,拿总的子集数量减去不满足的就是答案. 那么考虑不满足题意的点集. 首先如果对于一对点P和P1,让它们连线,以P为基准,相对度数为0度,枚举P和P1这个条线以上的所有…
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of nanoparticles called Amphiphilic Carbon Molecules (ACMs). ACMs are semiconductors. It means that they can be either conductors or insulators of elect…
任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O(n^2logN)就可以过了. 另外,本题有个很巧妙的技巧,就是一点等效与相反坐标的相反颜色的点. 第一次写,细节还是蛮多的,花了好久才搞清所有细节... 极角排序版,比较容易理解,932ms. #include<bits/stdc++.h> using namespace std; ; stru…
http://codeforces.com/problemset/problem/598/C 题目大意: 给你你个向量  向量的起点都是从(0,0)开始的   求哪个角最小  输出这两个向量 这是第一次接触极角 一个函数图像上某一点到原点的距离就是极径,极径与x轴的夹角就是极角 按照极角排序   是从第三象限的最右边的开始是最小  一直逆时针转到第二象限的最右边 求极角差最小就行了 但是卡精度问题  把double换成long double   就好了  (我也不知道为什么) #include<…
题目链接:http://codeforces.com/gym/102279/problem/H 大致题意: 你在一个定点,你有个长度为R的钩子,有n个东西在其他点处,问你能勾到的东西的数量是多少? 思路:明明一道几何题,罗老板居然用gcd巧妙的A了,真是太强了.如果一件物品挡住了另一件物品,那么它是勾不到的. 首先将所有距离在R的点都拎出来,然后对于给定点进行极角排序,最后俩俩相邻比较即可确定答案. AC代码: #include<cmath> #include<cstdio> #i…
题意:平面上有n个点,一只蚂蚁从最左下角的点出发,只能往逆时针方向走,走过的路线不能交叉,问最多能经过多少个点. 思路:每次都尽量往最外边走,每选取一个点后对剩余的点进行极角排序.(n个点必定能走完,这是凸包的性质决定的) #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> using namespace std;…
题目链接:http://poj.org/problem?id=1696 题意:给你n个点,然后我们用一条线把它们连起来,形成螺旋状: 首先找到左下方的一个点作为起点,然后以它为原点进行极角排序,找到极角最小的那个点,如果又多个选距离近的,每次都这样循环找n个点即可; #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> using namespace s…
链接 卡了几天的破题,对于hdu的那份数据,这就一神题.. 借助极角排序,枚举以每一个点进行极角排序,然后构造两条扫描线,一个上面一个下面,两条同时走,把上线和下线的点以及上线左边的点分别统计出来,如下图 样例3: 假如现在以d为p[0],那么所有可能结果一定是他与其他点的连线所分割的平面,那么首先以de为上线,下线的角度为上线+pi,两条线始终维护着这样的关系.de的下一个点为f,di的下一个点为c ,比较一下两者需要转的角度,选取较小角度转,注意一下相同的时候的处理. #include <i…
1285 - Drawing Simple Polygon   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Given set of points in the plane, your task is to draw a polygon using the points. You have to use all the points. To be more specific, each po…
题目传送门 题意:裸的对原点的极角排序,凸包貌似不行. /************************************************ * Author :Running_Time * Created Time :2015/11/3 星期二 14:46:47 * File Name :POJ_2007.cpp ************************************************/ #include <cstdio> #include <al…
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3077   Accepted: 1965 Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an a…
题目链接 题意 : 对输入的点极角排序 思路 : 极角排序方法 #include <iostream> #include <cmath> #include <stdio.h> #include <algorithm> using namespace std; struct point { double x,y; }p[],pp; double cross(point a,point b,point c) { return (a.x-c.x)*(b.y-c.y…
Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2489   Accepted: 1567 Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y19…
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x)+a.lr+b.rl,遍历完所有的点,问你最后的花费是多少 思路:每次选一个点的时候,在当前确定的每个点比较一下,选最短的距离. 为什么可以贪心?应为答案唯一,那么路径必定是唯一的,每个点所在的位置也一定是最短的. #include <bits/stdc++.h> using namespace…
如果,没有紫书上的翻译的话,我觉得我可能读不懂这道题.=_=|| 题意: 平面上有n个点,不是白点就是黑点.现在要放一条直线,使得直线一侧的白点与另一侧的黑点加起来数目最多.直线上的点可以看作位于直线的任意一侧. 分析: 首先假设直线经过两个点,否则可以移动直线使其经过两个点,并且总数不会减少. 所以,我们可以先枚举一个基点,然后以这个点为中心. 围绕基点将其他点按照极角排序,将直线旋转,统计符合要求的点的个数. 小技巧: 如果将所有的黑点以基点为中心做一个中心对称,则符合要求的点的个数就变成了…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5738 [题目大意] 给出平面中一些点,在同一直线的点可以划分为一个集合,问可以组成多少包含元素不少于2的集合. [题解] 最重要的还是处理点重合,和线重复计算的问题,对于每个点,进行极角排序,作为端点,然后统计包含它的每个集合即可.思路非常简单,然而比赛的时候……一脸懵逼地用map,pair,然后转战hash.看起来对于计算几何的敏感度还有待加强. [代码] #include <cstdio>…
/** 极角排序输出,,, 主要atan2(y,x) 容易失精度,,用 bool cmp(point a,point b){ 5 if(cross(a-tmp,b-tmp)>0) 6 return 1; 7 if(cross(a-tmp,b-tmp)==0) 8 return length(a-tmp)<length(b-tmp); 9 return 0; 10 } **/ #include <iostream> #include <algorithm> #includ…
题目链接:点击打开链接 题意: 给定二维坐标上的4个点 问: 找一个点使得这个点距离4个点的距离和最小 输出距离和. 思路: 若4个点不是凸4边形.则一定是端点最优. 否则就是2条对角线的交点最优,能够简单证明一下. 对于凸4边形则先极角排序一下. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef do…
Problem - D - Codeforces  Fix a Tree 看完第一名的代码,顿然醒悟... 我可以把所有单独的点全部当成线,那么只有线和环. 如果全是线的话,直接线的条数-1,便是操作数. 如果有环和线,环被打开的同时,接入到线上.那就是线和环的总数-1. 如果只有环的话,把所有的环打开,互相接入,共需n次操作. #include <cstdio> #include <algorithm> using namespace std; ; int cur[maxn];…
Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the…
Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4970   Accepted: 3100 Description The most exciting space discovery occurred at the end of the 20th century. In 1999, scientists traced down an ant-like creature in the planet Y19…
在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面积为 0.000. 长老们发现这个问题没有那么简单,于是委托你编程解决这个难题. 输入格式: 输入在第一行给出一个正整数 n(3 ≤n≤5000).随后 n 行,每行有两个整数,分别表示神石的横坐标.纵坐标(-109≤横坐标.纵坐标<109). 输出格式: 在一行中输出神坛的最小面积,四舍五入保留…
BZOJ 洛谷 考虑暴力,每次枚举三个点,答案就是\(\frac12\sum_{k<j<i}(i-k)\times(j-k)\). 注意到叉积有分配率,所以固定\(k\),枚举\(i,j\),\(Ans=\frac12\sum_{k<i}(i-k)\sum_{k<j<i}(j-k)\),前缀和即可. 还有个问题是叉积是有符号的.初始时将所有点按纵坐标排序,枚举\(k\)的时候将所有向量\(i-k\)按极角排序.因为\(i>k\),\(i\)都在\(k\)的上方,向量之间…