链接

之前刷poj计划时刷过,不过也没什么印象了。打铁还是趁热,还没热起来就放弃了,前面算是做了无用功,有如胡乱的看解题报告一样。

题目应该是比较经典的集合入门题,黑书上有一部分核心讲解。

题目中的最优光线必是要经过端点,这个黑书上提到了,应该也可以想到,然后就可以枚举一上一下的端点,判断它最长能走到哪里,首先可以判断出它是否能进的去第i个入口,

这个可以通过叉积进行判断上下点是不是在这条光线异侧,然后求直线的交点。

有一份好的模板很重要~

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 55
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {} //构造函数 方便代码编写
}p[N];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
pointt operator * (Point a,double b)
{
return Point(a.x*b,a.y*b);
}
pointt operator / (Point a,double b)
{
return Point(a.x/b,a.y/b);
}
bool operator < (const Point &a,const Point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
bool operator == (const Point &a,const Point &b)
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
//求点积以及利用点积求长度和夹角的函数
double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b,Point c)//差乘判左右 a->b与a->c向量的关系
{
return (a.x-c.x)*(a.y-b.y)-(a.y-c.y)*(a.x-b.x);
}
bool intersection1(Point p1, Point p2, Point p3, Point p4, Point& p) // 直线相交
{
double a1, b1, c1, a2, b2, c2, d;
a1 = p1.y - p2.y;
b1 = p2.x - p1.x;
c1 = p1.x*p2.y - p2.x*p1.y;
a2 = p3.y - p4.y;
b2 = p4.x - p3.x;
c2 = p3.x*p4.y - p4.x*p3.y;
d = a1*b2 - a2*b1;
if (!dcmp(d)) return false;
p.x = (-c1*b2 + c2*b1) / d;
p.y = (-a1*c2 + a2*c1) / d;
return true;
}
int main()
{
int n,i,j,g;
while(scanf("%d",&n)&&n)
{
for(i = ; i <= n ; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i+n].x = p[i].x;
p[i+n].y = p[i].y-1.0;
}
double ans = -INF;
int flag = ;
for(i = ; i <= n; i++)
{
for(j = n+ ; j <= *n ; j++)
{
if(j==n+i) continue;
Point sg ;
for(g = ; g <= n ; g++)
{
int d1 = dcmp(cross(p[i],p[j],p[g]));
int d2 = dcmp(cross(p[i],p[j],p[g+n]));
if(g==&&d1*d2<=) continue;
if(g==&&d1*d2>) break;
if(d1*d2>)
{
if(intersection1(p[i],p[j],p[g-],p[g],sg))
{
ans = max(ans,sg.x);
}
if(intersection1(p[i],p[j],p[n+g-],p[n+g],sg))
{
ans = max(ans,sg.x);
}
break;
}
}
if(g>n)
{
flag = ;
break;
}
}
if(flag) break;
}
if(flag) puts("Through all the pipe.");
else printf("%.2f\n",ans);
}
return ;
}

poj1039Pipe(直线交点、叉积)的更多相关文章

  1. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  2. POJ_1269_Intersecting Lines_求直线交点

    POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...

  3. hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)

    Area Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. hdu 1086 You can Solve a Geometry Problem too 求n条直线交点的个数

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  5. UVA 11178 Morley's Theorem(旋转+直线交点)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543 [思路] 旋转+直线交点 第一个计算几何题,照着书上代码打 ...

  6. ZOJ 1280 Interesting Lines | 求两直线交点

    原题: 求两直线交点 思路借鉴于:http://blog.csdn.net/zxy_snow/article/details/6341282 感谢大佬 #include<cstdio> # ...

  7. 计算几何——直线交点poj1269

    求直线交点还是要推一个公式的.. 见博客https://blog.csdn.net/u013050857/article/details/40923789 还要学一下向量的定点比分法 另外poj精度好 ...

  8. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

  9. poj1269(直线交点)

    传送门:Intersecting Lines 题意:给出N组直线,每组2条直线,求出直线是否相交.如果共线则输出LINE,相交则输入点坐标,否则输出NONE. 分析:模板裸题,直接上模板... #in ...

随机推荐

  1. Educational Codeforces Round 13 D:Iterated Linear Function(数论)

    http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...

  2. css杂记

    1,font-variant: 设置文本是否为小型的大写字母,值可以为normal,small-caps; 2,a:link: 未访问过的 a:visited: 访问过的 a:active: 活动的链 ...

  3. miniUI子窗口调父窗口方法

    window.Owner.XXX 其中XXX是父窗口里的方法名

  4. Django的第一个web程序及深入学习

    本学习历程参照Practical Django Projects和http://djangobook.py3k.cn上翻译的内容进行 注:本例以本机加以说明: 根据Django的安装过程可知:在命令行 ...

  5. 2015-09-17 001 存储过程数据操作类 H_data_Helper

    using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using S ...

  6. 山东理工大学第七届ACM校赛-飞花的线代 分类: 比赛 2015-06-26 10:29 10人阅读 评论(0) 收藏

    飞花的线代 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 飞花壕的线代一直非常的壕(好),线代考试每次都是全班第一.一次,飞花壕在预习 ...

  7. Unity5 Standard自发光材质无效解决方法

    受光物和发光物都要勾选Static才会有效. 如果不够选静态就是用HDR光照,需要相机勾选HDR 所以如果是动态的物体真实发光,Unity依旧无法支持

  8. 从客户端中检测到有潜在危险的Request.Form 值

    今天往MVC中加入了一个富文本编辑框,在提交信息的时候报了如下的错误:从客户端(Content="<EM ><STRONG ><U >这是测试这...&q ...

  9. NOIP 营业额统计 splay tree 纯模板

    2924: 营业额统计 Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByteTotal Submit: 389       ...

  10. 【Java】hashcode()和equals()

    大家知道,在集合中判断集合中的两个元素是否相同,依赖的是hashcode()和equals()两个方法. > 一个简单的实验 public class Teacher { private Int ...