poj 1066 Treasure Hunt
来源:互联网 发布:java工程师要多少钱 编辑:程序博客网 时间:2024/04/27 13:21
题目的意思就是从边界某个点出发到目标点问最少要和多少条线段相交。
枚举边界上的点判断就行了。
注意n=0时ans=1
CODE:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define oo 1e6#define eps 1e-8#define nMax 1000#define pb push_back#define bug puts("OOOOh.....");#define zero(x) (((x)>0?(x):-(x))<eps)int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1;}struct point { double x,y; point(double x=0,double y=0): x(x),y(y) {} void make(double _x,double _y) {x=_x;y=_y;} void read(){ scanf("%lf%lf",&x,&y); } double len(){ return sqrt(x*x+y*y); } friend point operator -(point const& u,point const& v) { return point(u.x-v.x,u.y-v.y); } friend point operator +(point const& u,point const& v) { return point(u.x+v.x,u.y+v.y); } friend double operator *(point const& u,point const& v) { return u.x*v.y-u.y*v.x; } friend double operator ^(point const& u,point const& v) { return u.x*v.x+u.y*v.y; } friend point operator *(double const& k,point const& v) { return point(k*v.x,k*v.y); } friend point operator /(point const& u,double const& k){ return point(u.x/k,u.y/k); } friend bool operator < (point const& u,point const& v) { if(dcmp(u.x-v.x) == 0) return dcmp(u.y-v.y)<0; return dcmp(u.x-v.x)<0; } friend bool operator == (point const& u,point const& v) { return (dcmp(u.x-v.x) == 0) && dcmp(u.y-v.y)==0; } friend int dots_online(point,point,point);};int dots_online(point a,point b,point c){ return dcmp((a-c)*(b-c))==0; }typedef struct line{ point a,b; line() {} line(point a,point b): a(a),b(b) {} void make(point _a,point _b) {a=_a;b=_b;} void read() { a.read(),b.read(); } friend int intersection(line,line);} segment;int dot_in_line(point p,line l){ return dcmp((l.a-p)*(p-l.b))==0 && dcmp((l.a-p)^(p-l.b))>=0;}int sameside(point a,point b,line l){ return dcmp((l.a-a)*(a-l.b)) * dcmp((l.a-b)*(b-l.b)) > 0;}int intersection(line u,line v){ if(dots_online(u.a,u.b,v.a) && dots_online(u.a,u.b,v.b)) return dot_in_line(u.a,v) || dot_in_line(u.b,v) || dot_in_line(v.a,u) || dot_in_line(v.a,u); else return !sameside(u.a,u.b,v) && !sameside(v.a,v.b,u);}int n,cnt;point p,p1,p2;line l[nMax];vector<point> s[4];int g[nMax][nMax];int main(){#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin);#endif scanf("%d",&n); for(int i=0;i<n;i++) { p1.read(),p2.read(); l[i].make(p1,p2); } p.read(); int ans = oo,f; if(n==0) ans=0; for(int i=0;i<n;i++) { segment s(p,l[i].a); f=0; for(int k=0;k<n;k++) if(!dot_in_line(s.b,l[k]) && intersection(s,l[k])) f++; if(ans>f) ans =f; s.b=l[i].b; f=0; for(int k=0;k<n;k++) if(!dot_in_line(s.b,l[k]) && intersection(s,l[k])) f++; ans = min(ans,f); } printf("Number of doors = %d\n",ans+1); return 0;}
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- poj-1066 Treasure Hunt
- Poj-1066-Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt 笔记
- zoj 1158 || poj 1066 Treasure Hunt
- JPA 提示Entity 设置主键问题
- ACM题 Biorhythms 将中国剩余定理的思想包含在程序中
- hdu 1754 线段树入门的题
- 字符串反转
- html学习心得
- poj 1066 Treasure Hunt
- 错误提示:org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: *
- Oracle—RMAN备份(三)
- 非深入探寻Java反射机制 (Fields)
- 学习总结——两个月的JAVA学习
- java hibernate 基础dao basedao
- 初探Vector
- but no declaration can be found for element 'authentication-manager'的一种解决办法
- jQuery 代码片段积累2( 50 )