Anger Begins&&http://acm.nbut.cn:8081/Contest/view/id/29/problem/A.xhtml
来源:互联网 发布:黑暗之魂 世界观知乎 编辑:程序博客网 时间:2024/05/19 10:41
题意:给你一些路的首尾坐标,求从A路是否能到达B路
思路:先判断线段是否相交建图,然后求多源多点最短路即可,
AC代码:
#include <iostream>#include<string.h>#include<algorithm>#include<cstdio>#define CLR(arr,val) memset(arr,val,sizeof(arr))using namespace std;#define N 105#define inf 1<<30#define Max(x, y)(x > y ? x : y)#define Min(x, y)(x < y ? x : y)typedef struct{ double x1; double y1; double x2; double y2;}Node;typedef struct{ double x; double y;}Point;Node node[N];int map[N][N];double Multi(Point p1, Point p2, Point p3)//叉乘判断点与线的位置关系{ return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);}bool Isintersect(Point a1, Point a2, Point b1, Point b2)//判断两条线段是否相交(含顶点){ if (Min(a1.x, a2.x) <= Max(b1.x, b2.x) && Min(a1.y, a2.y) <= Max(b1.y, b2.y) && Min(b1.x, b2.x) <= Max(a1.x, a2.x) && Min(b1.y, b2.y) <= Max(a1.y, a2.y) && Multi(a1, a2, b1) * Multi(a1, a2, b2) <= 0 && Multi(b1, b2, a1) * Multi(b1, b2, a2) <= 0 ) return true;//说明两线段之间相交 return false;}void in(int &a){ char ch; while((ch=getchar())<'0'||ch>'9'); for( a=0;ch>='0'&&ch<='9';ch=getchar()) a=a*10+ch-'0';}bool ok(int a,int b){ Point a1,b1,a2,b2; a1.x=node[a].x1,a1.y=node[a].y1; b1.x=node[a].x2,b1.y=node[a].y2; a2.x=node[b].x1,a2.y=node[b].y1; b2.x=node[b].x2,b2.y=node[b].y2; if(Isintersect(a1,b1,a2,b2)) return true; else return false;}int main(){ int n,m; while(~scanf("%d",&n)) { for(int i=1;i<=n;++i) scanf("%lf%lf%lf%lf",&node[i].x1,&node[i].y1,&node[i].x2,&node[i].y2); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) { if(ok(i,j)) map[i][j]=map[j][i]=1; else map[i][j]=map[j][i]=0; } in(m); for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(map[k][j]&&map[j][i]) map[k][i]=map[i][k]=1; for(int i=0;i!=m;++i) { int a,b; in(a),in(b); if(map[a][b]) puts("YES"); else puts("NO"); } } return 0;}
- Anger Begins&&http://acm.nbut.cn:8081/Contest/view/id/29/problem/A.xhtml
- http://acm.nbut.cn:8081/Problem/view.xhtml?id=1317&&线段树单点查询
- A - Millennium&&http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=9661#problem/A
- Enumerate the Triangles&&http://cdn.ac.nbutoj.com/Contest/view/id/14/problem/E.xhtml
- - Recurring Decimals&&http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=9661#problem/B
- Kids and Prizes 来源: <http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85996#problem/B>
- NBUT 2015 ACM Trainning Contest-11038 Problem A How many Points 解题报告
- NOJ [1313] Anger Begins
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1001&&纸牌游戏
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1003&&矩阵链乘
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1187&&Hole Breaker
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1186
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1184&&Elaine's Queue
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1182&&Counter-Strike
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1181
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1180
- http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1198&& I can do it!
- http://acm.pku.cn/JudgeOnline/problem?id=1141两种AC方法
- SQL JOIN TEST
- hdu 1247 字典树 Hat’s Words
- java-基础加强之枚举
- 【Android Training - 05】与其他Apps进行交互 [ Lesson 1 - 启动到另外一个app ]
- 硬盘方式安装redhat7
- Anger Begins&&http://acm.nbut.cn:8081/Contest/view/id/29/problem/A.xhtml
- 走出浮躁的泥沼:关于技术与工作
- 让窗体保持在最顶层实例
- VBS模拟Post上传文件失败
- 立波硬件检测:安卓手机硬件信息详细检测
- 网络流题解分布
- Servlet从入门到精通五
- 如何成为一名优秀的web前端工程师(前端攻城师)?
- 利用高权重平台 日引上万流量