ZOJ 1648Circuit Board
来源:互联网 发布:淘宝物流显示香港 编辑:程序博客网 时间:2024/06/05 11:46
On the circuit board, there are lots of circuit paths. We know the basic constrain is that no two path cross each other, for otherwise the board will be burned.
Now given a circuit diagram, your task is to lookup if there are some crossed paths. If not find, print "ok!", otherwise "burned!" in one line.
A circuit path is defined as a line segment on a plane with two endpoints p1(x1,y1) and p2(x2,y2).
You may assume that no two paths will cross each other at any of their endpoints.
Input
The input consists of several test cases. For each case, the first line contains an integer n(<=2000), the number of paths, then followed by n lines each with four float numbers x1, y1, x2, y2.
Output
If there are two paths crossing each other, output "burned!" in one line; otherwise output "ok!" in one line.
Sample Input
1
0 0 1 1
2
0 0 1 1
0 1 1 0
Sample Output
ok!
burned!
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<cmath>#include<map>#include<algorithm>using namespace std;typedef long long LL;#define rep(i,j,k) for (int i=j;i<=k;i++)#define per(i,j,k) for (int i=j;i>=k;i--)#define inone(x) scanf("%d",&x)#define intwo(x,y) scanf("%d%d",&x,&y)typedef pair<double,double> pii;const int N = 2005;const int INF=0x7FFFFFFF;int n;pii a[N],b[N];int check(int x,int y){ double l=max(a[x].first,a[y].first); double r=min(b[x].first,b[y].first); if (l > r) return 0; double ll=max(min(a[x].second,b[x].second),min(a[y].second,b[y].second)); double rr=min(max(a[x].second,b[x].second),max(a[y].second,b[y].second)); if (ll > rr) return 0; if (a[x].first==b[x].first) return 1; if (a[y].first==b[y].first) return 1; double k1=(a[x].second-b[x].second)/(a[x].first-b[x].first); double k2=(a[y].second-b[y].second)/(a[y].first-b[y].first); double d1=a[x].second+k1*(l-a[x].first)-a[y].second-k2*(l-a[y].first); double d2=a[x].second+k1*(r-a[x].first)-a[y].second-k2*(r-a[y].first); return d1*d2<=0;}int main(){ while (~inone(n)) { rep(i,1,n) { scanf("%lf%lf%lf%lf",&a[i].first,&a[i].second,&b[i].first,&b[i].second); if (a[i].first>b[i].first) swap(a[i],b[i]); else if (a[i].first==b[i].first&&a[i].second>b[i].second) swap(a[i],b[i]); } int flag=0; rep(i,1,n) { rep(j,i+1,n) { if (check(i,j)) {flag=1; break;} } if (flag) break; } puts(flag?"burned!":"ok!"); } return 0;}
- zoj 1648 Circuit Board
- zoj 1648 Circuit Board
- zoj 1648 Circuit Board
- zoj 1648 Circuit Board
- ZOJ 1648Circuit Board
- ZOJ 1648 Circuit Board(判断线段相交)
- ZOJ 1648 Circuit Board(线段相交判定)
- ZOJ 1648 Circuit Board(计算几何)
- ZOJ 1648:Circuit Board __判断两线段相交
- ZOJ 1648 Circuit Board【跨立实验判断线段相交】
- ZOJ 1648 Circuit Board计算几何(解题报告)
- zoj 1648 Circuit Board (判断线段是否相交)
- ZOJ 1648 Circuit Board(线段相交判定 刘汝佳模板)
- Circuit Board
- Circuit Board
- ZOJ--1648:Circuit Board(跨立实验线段判交)
- ZOJ1648 Circuit Board
- [CEOI2012]Printed Circuit Board
- 初识前端框架(Vue)打包遇到的坑~
- 《VR产业白皮书》
- 富士伺服电机速度转换公式
- C++编程调试秘笈(第1次阅读)
- .net导出excel 向客户端推送文件 下载文件 ClosedXML导出Excel NPOI导出Excel
- ZOJ 1648Circuit Board
- MyEclipse2014 Maven项目建立
- Aspect注解进行通知的配置
- highcharts坐标轴实现字符串换行
- 路由器测试的类型和方法
- IDEA实现热部署
- 不正经运维狗的文档1—14
- 二维码扫描、生成
- RecyclerView完全解析@Hongyang