HDU 1086 You can Solve a Geometry Problem too(判断两条直线是否相交)
来源:互联网 发布:视频剪辑软件免费下载 编辑:程序博客网 时间:2024/06/06 18:00
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1086
题解:
单纯的判断
AC代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct line{ double x1,x2,y1,y2;}ln[1000];int solve(int i, int j){ int flag = 0; double dac=(ln[i].x1-ln[j].x1)*(ln[i].y1-ln[i].y2)-(ln[i].x1-ln[i].x2)*(ln[i].y1-ln[j].y1); double dbc=(ln[i].x1-ln[j].x2)*(ln[i].y1-ln[i].y2)-(ln[i].x1-ln[i].x2)*(ln[i].y1-ln[j].y2); double acb=(ln[j].x1-ln[i].x1)*(ln[j].y1-ln[j].y2)-(ln[j].x1-ln[j].x2)*(ln[j].y1-ln[i].y1); double adb=(ln[j].x1-ln[i].x2)*(ln[j].y1-ln[j].y2)-(ln[j].x1-ln[j].x2)*(ln[j].y1-ln[i].y2); if(acb * adb <= 0) flag ++; if(dbc * dac <= 0) flag ++; if(flag == 2) return 1; else return 0;}int main(){ int t,ans; while(cin >> t) { if(t == 0)break; ans = 0; for(int i = 1; i <= t; i++) { cin >> ln[i].x1 >> ln[i].y1 >> ln[i].x2 >> ln[i].y2; } for(int i = 1; i < t; i++) { for(int j = i+1; j <= t; j++) { if(solve(i,j) == 1)ans++; } } cout << ans <<endl; } return 0;}
0 0
- HDU 1086 You can Solve a Geometry Problem too(判断两条直线是否相交)
- HDU 1086 You can Solve a Geometry Problem too 判断任意两线段是否相交
- HDU ACM 1086 You can Solve a Geometry Problem too->判断两线段是否相交
- HDU 1086 You can Solve a Geometry Problem too(判断两线段是否相交)跨立实验
- hdu You can Solve a Geometry Problem too(判断两条线段相交)
- HDU 1086 You can Solve a Geometry Problem too(判断线段是否相交,非规范相交)
- hdu1086 You can Solve a Geometry Problem too (判断两线段是否相交)
- hdu-1086 You can Solve a Geometry Problem too(线段是否相交)
- HDU 1086 You can Solve a Geometry Problem too(判断线段相交)
- HDU 1086 You can Solve a Geometry Problem too (计算几何 判断线段相交)
- You can Solve a Geometry Problem too----判断两线段是否相交
- You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交
- hdoj-1086-You can Solve a Geometry Problem too 判断线段是否相交
- 杭电 1086 You can Solve a Geometry Problem too 判断线段是否相交.
- HDU 1086 You can Solve a Geometry Problem too 两线段相交模板
- 线段是否相交问题 HDU 1086 You can Solve a Geometry Problem too
- [ACM] hdu You can Solve a Geometry Problem too (线段是否相交及交点个数)
- Hdu 1086 You can Solve a Geometry Problem too[判断线段相交,完整版]
- usaco 2.4 bessie come home
- 在android4.0及以前的版本如何去掉ListView/GridView下拉出空白回弹的效果
- grep
- jQuery选择器总结
- HUNNU 11317 Alice and Bob
- HDU 1086 You can Solve a Geometry Problem too(判断两条直线是否相交)
- lint工具的使用——相关的文档
- 《SQL Server 必知必会》读书笔记
- 【Algothrim】动态规划实例(0、1背包问题)
- 镜像串之字符串常量用处
- LeetCode#338 Counting Bits
- java mongo
- spring
- java设计模式之解释器模式