链接

之前刷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. symfony中twig的模板变量与注释

    程序会传递给模板若干变量,你需要在模板里输出他们.例如输出$hello .1{{ hello }}.如果传递给模板的是对象或者数组,你可以使用点. 来输出对象的属性或者方法,或者数组的成员.或者你可以 ...

  2. js声明

    var a = 2; //我们习惯把这条语句当做一条声明 但是js引擎把它当做两条声明. var a; //在编译时执行  同时var a;存在提升 a = 2;//在运行是执行  赋值lhs不会提升 ...

  3. java 模拟消息的发送功能

    import java.util.HashMap; import java.util.Iterator; import java.util.Map; /* * 完成消息的发送功能 * 在发送消息之前, ...

  4. layer

    一款实用的web提示框架!下面是实用这款框架的实例 html代码 <p class='layer_notice'>我们是否是好惹的</p> <input type=&qu ...

  5. python-day7 python内置模块 面向对象

    1.configparser模块 configparser用于处理特定格式的文件,其本质上是利用open来操作文件 # 注释1 ; 注释2 [section1] # 节点 k1 = v1 # 值 k2 ...

  6. grails-domain-id 无生成策略,由程序控制

    一 domain class 中标示 class Menu implements Comparable<Menu>{ String id; String name; } static co ...

  7. 在Visual Studio中使用MonoTouch开发iOS应用程序

    前段时间在工作机上装了Mac OS X,这主要是因为我最近需要开发iPhone应用程序.虽然Xcode,Objective C一定是开发iOS应用程序的主流,但是经过一番考虑,我还是决定尝试一下使用M ...

  8. SqlSever基础 print 在消息中输出hello world

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  9. Zabbix监控交换机设置

    说明: Zabbix监控服务端已经配置完成,现在要使用Zabbix对交换机进行监控. 具体操作: 以下操作在被监控的交换机上进行,这里以Cisco交换机为例. 一.登录到Cisco交换机,开启snmp ...

  10. 计算5的阶乘并在JSP页面输出

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...