前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布

hdu1086

作者头像
@坤的
发布2018-06-04 11:27:46
4160
发布2018-06-04 11:27:46
举报
文章被收录于专栏:*坤的Blog*坤的Blog

#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <algorithm> using namespace std; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f;

struct Line { double x1,y1,x2,y2; }node[105];

bool solve(Line a, Line b)//叉积判断两线段是否相交 { if (((a.x1-b.x1)*(a.y2-b.y1)-(a.x2-b.x1)*(a.y1-b.y1))*((a.x1-b.x2)*(a.y2-b.y2)-(a.x2-b.x2)*(a.y1-b.y2))>0) return false; if (((b.x1-a.x1)*(b.y2-a.y1)-(b.x2-a.x1)*(b.y1-a.y1))*((b.x1-a.x2)*(b.y2-a.y2)-(b.x2-a.x2)*(b.y1-a.y2))>0) return false; return true; }

int main () { int n; while (scanf ("%d",&n),n) { for (int i=0; i<n; i++) scanf ("%lf%lf%lf%lf",&node[i].x1,&node[i].y1,&node[i].x2,&node[i].y2); int cnt = 0; for (int i=0; i<n; i++) { for (int j=i+1; j<n; j++) { if (solve(node[i], node[j])) cnt++; } } printf ("%d\n",cnt); } return 0; }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-01-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档