zoukankan      html  css  js  c++  java
  • POJ 1066

    由于到达点时不能绕墙,因为这是无意义的,所以,两点间的最小墙依然是按照直线所穿过的墙计算。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    const double eps=0.000000001;
    struct point{
    	double x,y;
    }Point[100],des;
    struct edge{
    	point start,end;
    }Edge[100],Tmp;
    
    int ne,np;
    
    double multi(point p1,point p2, point p0){
        return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    }
     
    bool cross(edge v1, edge v2){
        if(max(v1.start.x,v1.end.x)>=min(v2.start.x,v2.end.x)&&
        max(v2.start.x,v2.end.x)>=min(v1.start.x,v1.end.x)&&
        max(v1.start.y,v1.end.y)>=min(v2.start.y,v2.end.y)&&
        max(v2.start.y,v2.end.y)>=min(v1.start.y,v1.end.y)&&
        multi(v2.start,v1.end,v1.start)*multi(v1.end,v2.end,v1.start)>eps&&
        multi(v1.start,v2.end,v2.start)*multi(v2.end,v1.end,v2.start)>eps)
        return true;
        return false;
    }
    
    
    int main(){
    	while(scanf("%d",&ne)!=EOF){
    		np=0;
    		for(int i=0;i<ne;i++){
    			scanf("%lf%lf",&Point[np].x,&Point[np].y);
    			np++;
    			scanf("%lf%lf",&Point[np].x,&Point[np].y);
    			np++;
    			Edge[i].start=Point[np-2]; Edge[i].end=Point[np-1];
    		}
    		Point[np].x=0; Point[np].y=0;
    		np++;
    		Point[np].x=0; Point[np].y=100;
    		np++;
    		Point[np].x=100; Point[np].y=0;
    		np++;
    		Point[np].x=100; Point[np].y=100;
    		np++;
    		scanf("%lf%lf",&des.x,&des.y);
    		int ans=1000,tmp;
    		for(int i=0;i<np;i++){
    			Tmp.start=des; Tmp.end=Point[i]; tmp=0;
    			for(int i=0;i<ne;i++){
    				if(cross(Tmp,Edge[i]))
    				tmp++;
    			}
    			ans=min(ans,tmp);
    		}
    		printf("Number of doors = %d
    ",ans+1);
    	}
    }
    

      

  • 相关阅读:
    Codeforces Round#410 Div.2
    AtCoder Beginner Contest-060
    如何将gedit变成c++编译器
    洛谷 P2486 [SDOI2011]染色
    让lu哥头痛了许久的代码(洛谷:树的统计)
    字符串模拟入门
    luogu P1553 数字反转(升级版)
    那些令人难忘的——坑
    luogu P1341 无序字母对
    最短路相关题目
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3872805.html
Copyright © 2011-2022 走看看