zoukankan      html  css  js  c++  java
  • G

    来源poj2074

    An architect is very proud of his new home and wants to be sure it can be seen by people passing by his property line along the street. The property contains various trees, shrubs, hedges, and other obstructions that may block the view. For the purpose of this problem, model the house, property line, and obstructions as straight lines parallel to the x axis:

    To satisfy the architect's need to know how visible the house is, you must write a program that accepts as input the locations of the house, property line, and surrounding obstructions and calculates the longest continuous portion of the property line from which the entire house can be seen, with no part blocked by any obstruction.

    Input

    Because each object is a line, it is represented in the input file with a left and right x coordinate followed by a single y coordinate:
    < x1 > < x2 > < y >
    Where x1, x2, and y are non-negative real numbers. x1 < x2
    An input file can describe the architecture and landscape of multiple houses. For each house, the first line will have the coordinates of the house. The second line will contain the coordinates of the property line. The third line will have a single integer that represents the number of obstructions, and the following lines will have the coordinates of the obstructions, one per line.
    Following the final house, a line "0 0 0" will end the file.
    For each house, the house will be above the property line (house y > property line y). No obstruction will overlap with the house or property line, e.g. if obstacle y = house y, you are guaranteed the entire range obstacle[x1, x2] does not intersect with house[x1, x2].

    Output

    For each house, your program should print a line containing the length of the longest continuous segment of the property line from which the entire house can be to a precision of 2 decimal places. If there is no section of the property line where the entire house can be seen, print "No View".

    Sample Input

    2 6 6
    0 15 0
    3
    1 2 1
    3 4 1
    12 13 1
    1 5 5
    0 10 0
    1
    0 15 1
    0 0 0

    Sample Output

    8.80
    No View

    cnm,什么垃圾poj,我debug半天没有找出来,然后不知道干嘛,瞎弄就过了,真的是;

    求一下哪些地方不能看到,然后把能看到的最大长度写下就可以

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<queue>
    #include<stack>
    #include<map>
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=a;i>=n;i--)
    typedef long long ll;
    typedef long double ld;
    const ll mod=1e9+100;
    const double E=exp(1.0);
    const double EPS=1e-6;
    using namespace std;
    const double pi=acos(-1.0);
    const int inf=0xfffffff;
    struct tnt
    {
    	double x1,x2,y;
    	double left,right;
    }h,a[1005],line;
    void solve(int n)
    {
    	rep(i,0,n)
    	{
    		if(h.y<=a[i].y||a[i].y<=line.y)
    		{
    			a[i].left=a[i].right=-1;
    			continue;
    		}
    		double du1=(h.x2-a[i].x1)/(h.y-a[i].y),du2=(h.x1-a[i].x2)/(h.y-a[i].y);
    		a[i].left=a[i].x1-du1*(a[i].y-line.y);
    		a[i].right=a[i].x2-du2*(a[i].y-line.y);
    	}
    }
    bool cmp(tnt a,tnt b) {	return a.left<b.left;}
    int main()
    {
    	int n;
    	while(~sf("%lf%lf%lf",&h.x1,&h.x2,&h.y))
    	{
    		if(h.x1+h.x2+h.y==0) return 0;
    		sf("%lf%lf%lf",&line.x1,&line.x2,&line.y); 
    		cin>>n;
    		rep(i,0,n)
    		sf("%lf%lf%lf",&a[i].x1,&a[i].x2,&a[i].y);
    		solve(n);
    		sort(a,a+n,cmp);
    		double last=0;
    		double len=0;
    		rep(i,0,n)
    		{
    			if(a[i].right <0||a[i].left >line.x2)continue;
    			if(a[i].left>last)
    			{
    				len=max(len,a[i].left-last);
    				last=a[i].right;
    			}else
    			last=max(last,a[i].right);
    		}
    		if(line.x2 >last)
    		len=max(len,line.x2-last);
    		if(len==0) pf("No View
    ");
    		else pf("%.2lf
    ",len+EPS);
    	}
    }
    
  • 相关阅读:
    洛谷P3376 【模板】网络最大流
    bzoj 4598: [Sdoi2016]模式字符串
    JAVA类(下)
    2019DDCTF部分Writeup
    Atom配置(VIM党) · iuunhao
    Tips
    rsync auth failed on module xxx
    基于mykernel完成时间片轮询多道进程的简单内核
    机器学习技法笔记(2)-Linear SVM
    css之制作三角形
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9433541.html
Copyright © 2011-2022 走看看