hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)

Pipe

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 240    Accepted Submission(s): 99

Problem Description

The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the design phase of the new pipe shape the company ran into the problem of determining how far the light can reach inside each component of the pipe. Note that the material which the pipe is made from is not transparent and not light reflecting.

Each pipe component consists of many straight pipes connected tightly together. For the programming purposes, the company developed the description of each component as a sequence of points [x1; y1], [x2; y2], . . ., [xn; yn], where x1 < x2 < . . . xn . These are the upper points of the pipe contour. The bottom points of the pipe contour consist of points with y-coordinate decreased by 1. To each upper point [xi; yi] there is a corresponding bottom point [xi; (yi)-1] (see picture above). The company wants to find, for each pipe component, the point with maximal x-coordinate that the light will reach. The light is emitted by a segment source with endpoints [x1; (y1)-1] and [x1; y1] (endpoints are emitting light too). Assume that the light is not bent at the pipe bent points and the bent points do not stop the light beam.

Input

The input file contains several blocks each describing one pipe component. Each block starts with the number of bent points 2 <= n <= 20 on separate line. Each of the next n lines contains a pair of real values xi, yi separated by space. The last block is denoted with n = 0.

Output

The output file contains lines corresponding to blocks in input file. To each block in the input file there is one line in the output file. Each such line contains either a real value, written with precision of two decimal places, or the message Through all the pipe.. The real value is the desired maximal x-coordinate of the point where the light can reach from the source for corresponding pipe component. If this value equals to xn, then the message Through all the pipe. will appear in the output file.

Sample Input

4
0 1
2 2
4 1
6 4
6
0 1
2 -0.6
5 -4.45
7 -5.57
12 -10.8
17 -16.55
0

Sample Output

4.67
Through all the pipe.

题解:中间找x点坐标还没理解,中间判断相交,以及与上下管道相交处理的很巧妙;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
struct Node{
    double x,y;
};
Node point[30][2];
double chaji(Node a,Node b,Node c){
    return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
double is_intersection(Node a,Node b,Node c,Node d){
    return chaji(a,b,c)*chaji(a,b,d);
}
double area(Node a,Node b,Node c){
    double ab,bc,ac;
    ab=sqrt(1.0*pow(b.x-a.x,2)+pow(b.y-a.y,2));
    ac=sqrt(1.0*pow(c.x-a.x,2)+pow(c.y-a.y,2));
    bc=sqrt(1.0*pow(c.x-b.x,2)+pow(c.y-b.y,2));
    double p=(ab+bc+ac)/2.0;//  /2
    return sqrt(p*(p-ac)*(p-ab)*(p-bc));
}
double getx(Node a,Node b,Node c,Node d){
    double s1=area(a,b,c),s2=area(a,b,d);
    return (s1*d.x+s2*c.x)/(s1+s2);//找x坐标,没理解太清;
}
int main(){
    int n;
    while(scanf("%d",&n),n){
        for(int i=0;i<n;i++){
            scanf("%lf%lf",&point[i][0].x,&point[i][0].y);
            point[i][1].x=point[i][0].x;
            point[i][1].y=point[i][0].y-1;
        }
        Node s_1=point[0][0],s_2=point[0][1],a,b;
        double ans=-INF;
        int flot=0;
        for(int q=0;q<n;q++){
            for(int w=0;w<2;w++){
                a=point[q][w];
                for(int e=q+1;e<n;e++){
                    for(int r=0;r<2;r++){
                        b=point[e][r];
                        if(is_intersection(a,b,s_1,s_2)<=0){
                            int t;
                            for(t=1;t<n;t++){
                                if(is_intersection(a,b,point[t][0],point[t][1])>0){
                                    double x;
                                    if(chaji(a,b,point[t][0])>0)
                                        x=getx(a,b,point[t-1][1],point[t][1]);
                                    else x=getx(a,b,point[t-1][0],point[t][0]);
                                    ans=max(ans,x);
                                    break;
                                }
                            }
                            if(t==n)flot=1;
                        }
                    }
                }
            }
        }
        if(flot)puts("Through all the pipe.");
        else printf("%.2f\n",ans);
    }
    return 0;
}
时间: 2024-08-02 02:36:36

hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)的相关文章

poj1039——计算几何 求直线与线段交点,判断两条直线是否相交

poj1039——计算几何  求直线与线段交点,判断两条直线是否相交 Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9439   Accepted: 2854 Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the de

poj1039(计算几何)线段相交

题意:给一个管道求光线能穿到的最大x坐标. 解法:通过旋转光线一定可以使得光线接触一个上点和一个下点.枚举接触的上下点,然后逐一判断光线是否穿过每个拐点面.碰到一个拐点面没有穿过的,则是因为与其左边线段相交,求出直线与线段交点更新答案即可.不想交则说明在前一个拐点已经穿出去了. 代码: /****************************************************** * author:xiefubao ********************************

【南阳OJ分类之语言入门】80题题目+AC代码汇总

声明: 题目部分皆为南阳OJ题目. 代码部分包含AC代码(可能不止一个)和最优代码,大部分都是本人写的,并且大部分为c代码和少部分c++代码and极少java代码,但基本都是c语言知识点,没有太多差别,可能代码有的写的比较丑,毕竟知识有限. 语言入门部分题基本都较为简单,是学习编程入门的很好练习,也是ACM的第一步,入门的最佳方法,望认真对待. 本文由csdn-jtahstu原创,转载请注明出处,欢迎志同道合的朋友一起交流学习.本人QQ:1373758426和csdn博客地址. now begi

进程间通信IPC—匿名管道(pipe)和命名管道(fifo)

管道内部如何实现-大小,组织方式,环形队列? 一.进程间通信有多种方式,本文主要讲解对管道的理解.管道分为匿名管道和命名管道. (1)管道( pipe ):又称匿名管道.是一种半双工的通信方式,数据只能单向流动,而且只能在具有亲缘关系的进程间使用.进程的亲缘关系通常是指父子进程关系. (2)命名管道 (named pipe或FIFO) : 有名管道也是半双工的通信方式,但是它允许无亲缘关系进程间的通信. 二.管道 1. 管道的特点: (1)管道是半双工的,数据只能向一个方向流动:双方通信时,需要

Linux进程间通信之管道(pipe)、命名管道(FIFO)与信号(Signal)

整理自网络 Unix IPC包括:管道(pipe).命名管道(FIFO)与信号(Signal) 管道(pipe) 管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具有的功能外,它还允许无亲缘关系进程间的通信: 实现机制: 管道是由内核管理的一个缓冲区,相当于我们放入内存中的一个纸条.管道的一端连接一个进程的输出.这个进程会向管道中放入信息.管道的另一端连接一个进程的输入,这个进程取出被放入管道的信息.一个缓冲区不需要很大,它被设计成为环形的数据结构,以便管

Kruskal 2015百度之星初赛2 HDOJ 5253 连接的管道

题目传送门 1 /* 2 最小生成树(Kruskal):以权值为头,带入两个端点,自然的排序;感觉结构体的并查集很好看 3 注意:题目老头要的是两个农田的高度差,中文水平不好,题意理解成和平均值的高度差! 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <vector> 10 #include &l

【南阳OJ分类之大数问题】题目+AC代码汇总

声明:题目部分皆为南阳OJ题目,代码部分包含AC代码(可能不止一个)和标程. 由于大数问题用c/c++写比较麻烦,而Java的大数类又很好用,所以基本为java代码.实际上竞赛很少会考大数问题,因为竞赛是比的算法,而不是语言特性,不过很多都是大数据,数据上千万级别的,所以算法又很关键,显然那和这篇博客也没啥关系. 题目不是太难,大家和本人就权当学习或复习下Java吧O(∩_∩)O~. 该分类南阳oj地址:http://acm.nyist.edu.cn/JudgeOnline/problemset

有趣的库:pipe(类似linux | 管道)库

pipe并不是Python内置的库,如果你安装了easy_install,直接可以安装它,否则你需要自己下载它:http://pypi.python.org/pypi/pipe 之所以要介绍这个库,是因为它向我们展示了一种很有新意的使用迭代器和生成器的方式:流.pipe将可迭代的数据看成是流,类似于linux,pipe使用’|'传递数据流,并且定义了一系列的“流处理”函数用于接受并处理数据流,并最终再次输出数据流或者是将数据流归纳得到一个结果.我们来看一些例子. 第一个,非常简单的,使用add求

南阳OJ 61 传纸条(一)

传纸条(一) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5 描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的是,他们可以通过传纸条来进行交流.纸条要经由许多同学传到对方手里,小渊坐在矩阵的左上角,坐标(1,1),小轩坐在矩阵的右下角,坐标(m,n).从小渊传到小轩的纸条只可以向下或者向右传递,从小轩传给小渊的纸条只可以向上或者