【二分+半平面交】 HDOJ 3761 Jungle Outpost
来源:互联网 发布:growcut算法 编辑:程序博客网 时间:2024/05/29 12:45
注意到每次去点都是连续的就好做了。。。。
#include <iostream> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits> #include <cstdlib>#include <cmath>#include <time.h>#define maxn 50005#define maxm 3000005#define eps 1e-10#define mod 998244353#define INF 999999999#define lowbit(x) (x&(-x))#define mp mark_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R#define debug(x) printf("AA x = %d BB\n", x);//#pragma comment (linker,"/STACK:102400000,102400000")typedef long long LL;//typedef int LL;using namespace std;LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='\n')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}// headstruct Point{double x, y;Point(double x = 0, double y = 0) : x(x), y(y) { }};typedef Point Vector;struct Line{Point P;Vector v;double ang;Line() {}Line(Point P, Vector v) : P(P), v(v) { ang = atan2(v.y, v.x); }bool operator < (const Line &L) const {return ang < L.ang;}};Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}Vector operator - (Vector A, Vector B){return Vector(A.x - B.x, A.y - B.y);}Vector operator * (Vector A, double p){return Vector(A.x * p, A.y * p);}Vector operator / (Vector A, double p){return Vector(A.x / p, A.y / p);}int dcmp(double x){if(fabs(x) < eps) return 0;else return x < 0 ? -1 : 1;}double Dot(Vector A, Vector B){return A.x * B.x + A.y * B.y;}double Length(Vector A){return sqrt(Dot(A, A));}double Angle(Vector A, Vector B){return acos(Dot(A, B) / Length(A) / Length(B));}double Cross(Vector A, Vector B){return A.x * B.y - A.y * B.x;}double Area2(Point A, Point B, Point C){return Cross(B - A, C - A);}Vector Rotate(Vector A, double rad){return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));}Vector Normal(Vector A){double L = Length(A);return Vector(-A.y / L, A.x / L);}bool OnLeft(Line L, Point p){return Cross(L.v, p - L.P) > 0;}Point GetIntersection(Line a, Line b){Vector u = a.P - b.P;double t = Cross(b.v, u) / Cross(a.v, b.v);return a.P + a.v * t;}Point p[maxn];Line q[maxn];int HalfplaneInersection(Line* L, int n, Point* poly){//sort(L, L+n);int first, last;q[first = last = 0] = L[0];for(int i = 1; i < n; i++) {while(first < last && !OnLeft(L[i], p[last - 1])) last--;while(first < last && !OnLeft(L[i], p[first])) first++;q[++last] = L[i];if(fabs(Cross(q[last].v, q[last-1].v)) < eps) {last--;if(OnLeft(q[last], L[i].P)) q[last] = L[i];}if(first < last) p[last-1] = GetIntersection(q[last-1], q[last]);}while(first < last && !OnLeft(q[first], p[last-1])) last--;if(last - first <= 1) return 0;p[last] = GetIntersection(q[last], q[first]);int m = 0;for(int i = first; i <= last; i++) poly[m++] = p[i];return m;}Point po[maxn], poly[maxn];Vector v[maxn];Line line[maxn];int n;void read(void){scanf("%d", &n);for(int i = n-1; i >= 0; i--) scanf("%lf%lf", &po[i].x, &po[i].y);}bool check(int x){for(int i = 0; i < n; i++) {line[i].P = po[i];line[i].v = po[(i+x)%n] - po[i];}int k = HalfplaneInersection(line, n, poly);if(k) return true;else return false;}void work(void){int bot = 0, top = n-1, mid, res;while(top >= bot) {mid = (top+bot)>>1;if(check(mid)) bot = mid+1, res = mid;else top = mid-1;}printf("%d\n", res);}int main(void){int _;while(scanf("%d", &_)!=EOF) {while(_--) {read();work();}}return 0;}
0 0
- 【二分+半平面交】 HDOJ 3761 Jungle Outpost
- HDU 3761 Jungle Outpost(二分+半平面交)
- LA 4492 Jungle Outpost 半平面交,二分答案
- UVA 1475 Jungle Outpost(二分+半平面交)
- UVA 1475 - Jungle Outpost(二分 + 半平面交)
- POJ 3968|UVALive 4992|HDU 3761|UVA 1475|Jungle Outpost|二分|半平面交
- LA4992 Jungle Outpost 半平面交
- LA 4992 Jungle Outpost 半平面交 -
- uva 1475 - Jungle Outpost(二分+平面相交)
- HDU 3761 (二分 半平面交)
- poj3525 二分+半平面交
- 【半平面交】 HDOJ 1632 Polygons
- poj 3525 二分+半平面交
- POJ3525(二分+半平面交)
- POJ 3525 二分+半平面交
- UVA LA3890 二分和半平面交
- uvalive 4992(半平面交+二分)
- UVALive 3890 (半平面交 二分)
- ADF工具类:TaskFlowUtils.java 源代码
- AspectJ学习笔记1-报Invalid aspectj.home.的处理方法
- 组件自动绑定到Managed Bean功能
- 杭电1059 Dividing(多重背包解法)
- Jquery超简单遮罩层实现代码
- 【二分+半平面交】 HDOJ 3761 Jungle Outpost
- 用python实现wireshark的follow tcp stream功能
- 404页面是怎样对网站优化产生影响的?
- bash的RANDOM变量生成的是真正的随机数吗
- STL之map
- android:xml解析
- Task Flow使用指南之十:通过程序调用TaskFlow
- 10 个迅速提升你 Git 水平的提示
- android获取图片的旋转角度