HDU 1086 You can Solve a Geometry Problem too
来源:互联网 发布:分析数据的统计处理 编辑:程序博客网 时间:2024/05/16 02:58
题目来源:点击打开链接
两个线段AB和CD相交,需满足两个条件:
1、 A、B在线段CD两侧;((ab-ac)*(ad-ab)>=0))
2、C、D在线段AB两侧; ((cd-ca)*(cb-cd)>=0))
注:小写字母代表向量。
#include<iostream>using namespace std;struct node{ double x1,y1,x2,y2;}t[105];//每个线段封装一个结构体。int n;double mc(double x1,double y1,double x2,double y2){ return x1*y2-x2*y1;//两个向量共线的条件。}bool judge(int i,int j){ double a = mc(t[i].x1 - t[j].x1, t[i].y1 - t[j].y1, t[i].x1 - t[i].x2, t[i].y1 - t[i].y2); double b = mc(t[i].x1 - t[i].x2, t[i].y1 - t[i].y2, t[i].x1 - t[j].x2, t[i].y1 - t[j].y2); a = a * b; double c = mc(t[j].x1 - t[i].x1, t[j].y1 - t[i].y1, t[j].x1 - t[j].x2, t[j].y1 - t[j].y2); double d = mc(t[j].x1 - t[j].x2, t[j].y1 - t[j].y2, t[j].x1 - t[i].x2, t[j].y1 - t[i].y2); c = c * d; if(a >= 0 && c >= 0) return true; return false; }int main() { while(cin >> n&&n) { for(int i = 0; i < n; i++) cin >> t[i].x1 >> t[i].y1 >> t[i].x2 >> t[i].y2; int count = 0; for(int i = 0; i < n; i++) //从第一条边开始,判断是否与其它边是否有交点。 { for(int j = i + 1; j < n; j++) //j从i+1开始为了避免把某些交点算两次。 if(judge(i, j)) count++; } cout << count << endl; } return 0; }
0 0
- 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
- 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
- hdu/hdoj 1086 You can Solve a Geometry Problem too
- hdu-1086You 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 1086You 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
- 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
- HDU 1086 You can Solve a Geometry Problem too
- Eclipse上GIT插件EGIT使用手册
- Mac装Xcode后开不了机
- Server at localhost was unable to start within 45 seconds
- Keychain介绍、使用Snoop-it分析Keychain读写、使用Keychain Dumper导出Keychain中的数据 - iOS开发
- 4.【cocos2d-x-2.2.1】场景切换
- HDU 1086 You can Solve a Geometry Problem too
- homework of numerical solution of PDEs
- QML
- 机器没有网络,主机与虚拟机如何设定IP
- Linux环境下提升普通用户权限(sudo)
- elasticsearch使用记录
- PowerPoint颠覆者Prezi 5个月增长1000万用户,总用户突破4000万
- oracle创建对象、删除对象操作
- Eclipse快捷键大全