HDU
来源:互联网 发布:婚礼vcr制作软件 编辑:程序博客网 时间:2024/06/15 00:05
枚举判断线段相交
6个条件判相交(叉积)
跟上篇博客差不多
#include<iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>#include<set>#include<queue>#include<stack>#include<map>#define PI acos(-1.0)#define in freopen("in.txt", "r", stdin)#define out freopen("out.txt", "w", stdout)using namespace std;typedef long long ll;typedef unsigned long long ull;const int maxn = 100 + 7, maxd = 100 + 7, mod = 1e9 + 7;const ll INF = 0x7f7f7f7f;int n;struct node { double x, y;}a[maxn], b[maxn];double area(node a, node b, node c) { return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);}bool is_inter(node a, node b, node c, node d) { if( max(a.x, b.x) >= min(c.x, d.x) && max(c.x, d.x) >= min(a.x, b.x) && max(a.y, b.y) >= min(c.y, d.y) && max(c.y, d.y) >= min(a.y, d.y) && area(a, b, c) * area(a, b, d) <= 0 && area(c, d, a) * area(c, d, b) <= 0 ) return 1; return 0;}int solve() { int ans = 0; for(int i = 1; i < n; ++i) { for(int j = i+1; j <= n; ++j) { if(is_inter(a[i], b[i], a[j], b[j])) ans++; //cout << ans << endl; } } return ans;}int main() { while(~scanf("%d", &n) && n) { for(int i = 1; i <= n; ++i) { scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &b[i].x, &b[i].y); } //cout << " ==== " << endl; printf("%d\n", solve()); } return 0;}
阅读全文
1 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- uboot版本文件结构的更新改变
- c语言:字符串的连接,复制,长度
- c++中 gets(s)、scanf(%s) 、getline(s)、cin >> s 比较
- 自动化安装虚拟机
- C语言位操作中指定的某一位数置0、置1、取反
- HDU
- 深入浅出JMS(一)--JMS基本概念
- 我的电路实践
- bat命令备份oracle数据库,并且删除7天之前的数据文件
- 大话数据结构第四章栈十个问题及解答
- Termux的基础知识
- Linux基础练习(五)
- 巧用匿名函数重构你的代码
- EasyNVR HLS 、RTMP网页直播方案前端完善:监听表单变动