题目链接:点击打开链接

gg。。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;
#define ll int
#define point Point
const double eps = 1e-8;
const double PI = acos(-1.0);
double ABS(double x){return x>0?x:-x;}
int sgn(double x){
if(fabs(x) < eps)return 0;
if(x<0)return -1;
return 1;
}
struct Point
{
double x, y;
void put(){printf("%.0f,%.0f\n",x,y);}
Point(){}
Point(double _x, double _y){
x = _x; y = _y;
}
Point operator - (const Point & b)const{
return Point(x-b.x, y-b.y);
}
double operator ^ (const Point &b) const{
return x*b.y - y*b.x;
}
double operator *(const Point &b) const{
return x*b.x + y*b.y;
}
void transXY(double B){
double tx = x, ty = y;
x = tx*cos(B) - ty*sin(B);
y = tx*sin(B) + ty*cos(B);
}
};
double dist(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
struct Line
{
Point s,e;
double len(){return dist(s,e);}
Line(){}
Line(Point _s, Point _e)
{
s = _s; e = _e;
}
pair<int,Point> operator & (const Line &b) const{
Point res = s;
if(sgn((s-e) ^ (b.s-b.e)) == 0)
{
if(sgn((s-b.e) ^ (b.s-b.e)) == 0)
return make_pair(0,res);
else return make_pair(1,res);
}
double t = ((s-b.s) ^ (b.s-b.e)) / ((s-e)^(b.s-b.e));
res.x += (e.x - s.x) *t;
res.y += (e.y - s.y) *t;
return make_pair(2, res);
}
};
double cross(point a, point b, point c) {
return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);
}
bool intersect(Line l1, Line l2) {
return
max(l1.s.x, l1.e.x) > (min(l2.s.x, l2.e.x)-eps) &&
max(l2.s.x, l2.e.x) > (min(l1.s.x, l1.e.x)-eps) &&
max(l1.s.y, l1.e.y) > (min(l2.s.y, l2.e.y)-eps) &&
max(l2.s.y, l2.e.y) > (min(l1.s.y, l1.e.y)-eps) &&
(cross(l2.s, l1.e, l1.s) * cross(l1.e, l2.e, l1.s) > -eps) &&
(cross(l1.s, l2.e, l2.s) * cross(l2.e, l1.e, l2.s) > -eps);
}
bool online(Line l, point P) {
return (fabs(cross(l.e, P, l.s)) < eps) &&
((((P.x > l.s.x - eps) && (P.x < l.e.x + eps)) || ((P.x > l.e.x - eps) && (P.x < l.s.x+eps)))&&
(((P.y > l.s.y - eps) && (P.y < l.e.y + eps)) || ((P.y > l.e.y - eps) && (P.y < l.s.y +eps))));
}
bool inter(Line u, Line v){
return ((intersect(u, v)) && (!online(u, v.s)) && (!online(u, v.e)) && (!online(v, u.s)) && (!online(v, u.e)));
}
point S, T, A, B, C;
Line AB, BC, ST, AC, SA, SB, SC, TA, TB, TC;
double ans;
bool ok(Line x){
if(inter(x, AB))return false;
if(inter(x, BC))return false;
return true;
}
double d[5][5];
void addedge()
{
for (int i=0;i<5;i++)
for (int j=0;j<5;j++)
{
if (i==j) d[i][j]=0;
else d[i][j]=1e8;
} if (!inter(SA, BC))
{
d[0][1]=d[1][0]=min(d[0][1],dist(S,A));
}
//d[0][2]=d[2][0]=min(d[0][2],dis(S,B)); d[1][2]=d[2][1]=min(d[1][2],dist(A,B));
d[1][3]=d[3][1]=min(d[1][3],dist(A,C));
d[2][3]=d[3][2]=min(d[2][3],dist(B,C)); if (!inter(SC,AB))
{
d[0][3]=d[3][0]=min(d[0][3],dist(S,C));
} if (!intersect(ST,AB) && !intersect(ST,BC))
{
d[0][4]=d[4][0]=min(d[0][4],dist(S,T));
}
//printf("1->4 %d\n",is_inter(A,T,B,C));
if (!inter(TA,BC))
{
d[1][4]=d[4][1]=min(d[1][4],dist(A,T));
} if (cross(B,A,T)*cross(B,C,T)>-eps)
{
d[2][4]=d[4][2]=min(d[2][4],dist(B,T));
} if (cross(S,A,B)*cross(S,C,B)>-eps)
{
d[0][2]=d[2][0]=min(d[0][2],dist(S,B));
} if (!inter(TC,AB))
{
d[3][4]=d[4][3]=min(d[3][4],dist(C,T));
} }
int main(){
int i, j, k, cas;scanf("%d",&cas);
while(cas--) {
scanf("%lf %lf", &S.x, &S.y);
scanf("%lf %lf", &T.x, &T.y);
scanf("%lf %lf", &A.x, &A.y);
scanf("%lf %lf", &B.x, &B.y);
scanf("%lf %lf", &C.x, &C.y);
AB = Line(A,B); BC = Line(B,C); ST = Line(S,T); AC = Line(A,C);
SA = Line(S,A); SB = Line(S,B); SC = Line(S,C);
TA = Line(T,A); TB = Line(T,B); TC = Line(T,C);
addedge();
for(i = 0; i < 5; i++)
for(j = 0; j < 5; j++)
for(k = 0; k < 5; k++)
d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
printf("%.8f\n", d[0][4]);
}
return 0;
}
/* */

URAL 1750 Pakhom and the Gully 计算几何+floyd的更多相关文章

  1. BZOJ 1027 JSOI2007 合金 计算几何+Floyd

    题目大意:给定一些合金,选择最少的合金,使这些合金能够按比例合成要求的合金 首先这题的想法特别奇异 看这题干怎么会想到计算几何 并且计算几何又怎么会跟Floyd挂边 好强大 首先因为a+b+c=1 所 ...

  2. hdu 4606 简单计算几何+floyd+最小路径覆盖

    思路:将所有的直线的两个端点和城市混在一起,将能直接到达的两个点连线,求一次floyd最短路径.二分枚举bag容量,然后按给的要先后占领的城市由前向后,把能到一步到达的建一条边.然后求一次最小路径覆盖 ...

  3. BZOJ_1027_[JSOI2007]_合金_(计算几何+Floyd求最小环)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1027 共三种金属,\(m\)种材料,给出每种材料中三种金属的占比. 给出\(n\)种合金的三种 ...

  4. bzoj 1027 [JSOI2007]合金(计算几何+floyd最小环)

    1027: [JSOI2007]合金 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 2970  Solved: 787[Submit][Status][ ...

  5. BZOJ1027 [JSOI2007]合金 【计算几何 + floyd】

    题目 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的 原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金的 ...

  6. 【JZOJ5094】【GDSOI2017第四轮模拟day3】鸽子 计算几何+floyd

    题面 养鸽人要监视他的鸽子,有n只鸽子站在平面上,他可以在m个给定的点上设置监视器,如果一只鸽子在某个监视器上或者在两个监视器所连直线上或者在三个监视器所连直线的三角形内则其就咕咕咕了,现在养鸽人要让 ...

  7. URAL 2099 Space Invader题解 (计算几何)

    啥也不说了,直接看图吧…… 代码如下: #include<stdio.h> #include<iostream> #include<math.h> using na ...

  8. BZOJ 1027: [JSOI2007]合金 (计算几何+Floyd求最小环)

    题解就看这位仁兄的吧-不过代码还是别看他的了- 同样的方法-我200ms,他2000ms. 常数的幽怨- CODE #include <bits/stdc++.h> using names ...

  9. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

随机推荐

  1. 谜题27:变幻莫测的i值

    与谜题26中的程序一样,下面的程序也包含了一个记录在终止前有多少次迭代的循环.与那个程序不同的是,这个程序使用的是左移操作符(<<).你的任务照旧是要指出这个程序将打印什么.当你阅读这个程 ...

  2. 【博弈论】poj2484 A Funny Game

    如果当前状态可以根据某条轴线把硬币分成两个相同的组,则当前状态是必败态. 因为不论在其中一组我们采取任何策略,对方都可以采取相同的策略,如此循环,对方必然抽走最后一枚硬币. 因为我们先手,因此抽完后盘 ...

  3. 【R笔记】给R加个编译器——notepad++

    R的日记-给R加个编译器 转载▼ R是一款强大免费且开源的统计分析软件,这是R的长处,可也是其“缺陷”的根源:不似商业软件那样user-friendly.记得初学R时,给我留下最深印象的不是其功能的强 ...

  4. Hadoop下大矩阵乘法Version2

    1)使用本方法计算F*B,其中F是1000*1000的矩阵,B是1000*20000的矩阵,使用三个节点的集群,每个节点一个CPU核(集群装在虚拟机里,宿主机只有4个CPU核),每个节点配置一个map ...

  5. Xcode升级后导致插件不能用, 一句代码更新UUID OK~

      find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | ...

  6. js时间小总结

    1.js获取时间 var myDate = new Date(); 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份 ...

  7. RMAN 备份恢复 删除表空间后控制文件丢失

    先备份一个控制文件 RMAN> backup current controlfile tag='bak_ctlfile' format='/home/oracle/backup/bak_ctl_ ...

  8. XSS-Proxy之技术总结

    今天看了大风的文章,关于Cross Iframe Trick的思路.让我想到了曾经看到的关于XSS Proxy的一些文章. Advanced Cross-Site-Scripting with Rea ...

  9. 我使用过的Linux命令之swig - 把C/C++的代码嵌入Java等语言的开发工具

    用途说明 SWIG是Simplified Wrapper and Interface Generator的缩写,其官方站点是http://www.swig.org/.SWIG是个帮助使用C或者C++编 ...

  10. Java练习:tips.Print

    在学习Java时和<编程导论(Java)>中,大量使用了重载的System.out.println()等类似的输出语句.特别是书籍中,一行语句中包括System.out.println会显 ...