程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> poj 1039 Pipe (計算幾何)

poj 1039 Pipe (計算幾何)

編輯:C++入門知識

poj 1039 Pipe (計算幾何)


Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9110 Accepted: 2755

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 purpZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc2VzLCB0aGUgY29tcGFueSBkZXZlbG9wZWQgdGhlIGRlc2NyaXB0aW9uIG9mIGVhY2ggY29tcG9uZW50IGFzIGEgc2VxdWVuY2Ugb2YgcG9pbnRzIFt4MTsgeTFdLCBbeDI7IHkyXSwgLiAuIC4sIFt4bjsgeW5dLCB3aGVyZSB4MSA8IHgyIDwgLiAuIC4geG4gLiBUaGVzZQogYXJlIHRoZSB1cHBlciBwb2ludHMgb2YgdGhlIHBpcGUgY29udG91ci4gVGhlIGJvdHRvbSBwb2ludHMgb2YgdGhlIHBpcGUgY29udG91ciBjb25zaXN0IG9mIHBvaW50cyB3aXRoIHktY29vcmRpbmF0ZSBkZWNyZWFzZWQgYnkgMS4gVG8gZWFjaCB1cHBlciBwb2ludCBbeGk7IHlpXSB0aGVyZSBpcyBhIGNvcnJlc3BvbmRpbmcgYm90dG9tIHBvaW50IFt4aTsgKHlpKS0xXSAoc2VlIHBpY3R1cmUgYWJvdmUpLiBUaGUgY29tcGFueSB3YW50cyB0byBmaW5kLAogZm9yIGVhY2ggcGlwZSBjb21wb25lbnQsIHRoZSBwb2ludCB3aXRoIG1heGltYWwgeC1jb29yZGluYXRlIHRoYXQgdGhlIGxpZ2h0IHdpbGwgcmVhY2guIFRoZSBsaWdodCBpcyBlbWl0dGVkIGJ5IGEgc2VnbWVudCBzb3VyY2Ugd2l0aCBlbmRwb2ludHMgW3gxOyAoeTEpLTFdIGFuZCBbeDE7IHkxXSAoZW5kcG9pbnRzIGFyZSBlbWl0dGluZyBsaWdodCB0b28pLiBBc3N1bWUgdGhhdCB0aGUgbGlnaHQgaXMgbm90IGJlbnQgYXQgdGhlIHBpcGUgYmVudAogcG9pbnRzIGFuZCB0aGUgYmVudCBwb2ludHMgZG8gbm90IHN0b3AgdGhlIGxpZ2h0IGJlYW0uCjxwIGNsYXNzPQ=="pst">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.

思路:計算幾何。從結果反過來可以證:如果一根光線沒有擦到2個頂點,那肯定不是最優的解(可以移動或旋轉取到一個更優解)。枚舉上下兩個頂點成光線所在直線,然後判斷光線是否能合法,合法的話求出它射到的最遠距離


#include"stdio.h"
#include"string.h"
#include"math.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define LL __int64
#define N 30
const double eps=1e-8;
#define max(a,b) ((a)>(b)?(a):(b))
struct point  //存儲點坐標
{
    double x,y;
}up[N],down[N];
double ans;
int n;
double Cross(point a,point b,point c)      //叉積判斷點與直線位置關系
{                                          //若點在直線逆時針方向,返回正值
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
bool fun(point a,point b,int m)
{
    int i,sign;
    double x1,x2,x3,x4,y1,y2,y3,y4,aa,bb,cc,dd,x;
    for(i=0;ieps)      //管道底在直線上方
        {
            sign=2;break;
        }
    }
    if(i==n)    
        return true;
    if(i



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved