判断线段与直线的相交  这里有个地方需要注意的就是在 转换的时候容易报错 在叉积完后的判断符号的时候需要注意 这个地方会超出int 的范围

2014-06-0320:14:04

#include <iostream>
#include <cstdio>
#include <string.h>
#include <cmath>
using namespace std;
struct point{
int x,y;
point(int a = , int b = ){
x =a ; y = b;
}
}R[];
point operator - (const point a ,const point b){
return point ( a.x - b.x , a.y - b.y );
}
struct line{
point a,b;
}T[ ];
int n;
int cross( point a, point b){
return a.x*b.y - b.x* a.y;
} bool eq(point a,point b){
if(a.x == b.x&&a.y == b.y) return true;
else return false;
}
int maxv(int a, int b){
return a>b?a:b;
}
int jj(int a){
if(a>) return ;
if(a<) return -;
else return ;
}
int main()
{
int t ;
scanf("%d",&t);
while(t --){
scanf("%d",&n);
int num = ;
for( int i = ; i < n ; i++){
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
T[i].a=point(x1,y1);
T[i].b= point(x2,y2);
R[num++] = T[i].a;
R[num++] =T[i].b;
}
int ans =;
for( int i = ; i <num ; ++i){
for(int j = i+ ; j < num ; j++ ){
if(eq(R[i],R[j])) continue;
int ge = ;
line an;
an.a = R[i];
an.b = R[j]-an.a;
for(int k = ; k < n ; k ++){ int t1 =jj(cross( an.b , T[k].a - an.a ));
int t2 =jj(cross( an.b , T[k].b - an.a )); if(t1 * t2 <= ) ge++;
}
ans =maxv(ans,ge);
} } printf("%d\n",ans);
} return ;
}

ac1097的更多相关文章

随机推荐

  1. jenkins或ansible启动应用不成功日志又不报错

    碰到ansible无法起停tomcat的时候,有3个点需要关注 1.环境变量,在startup.sh中添加source /etc/profile 2.后台运行,加上nohup...& 3.单独 ...

  2. Unity3D NGUI 二 NGUI Button怎样接受用户点击并调用函数,具体方法名称是什么

    a.直接监听事件 把下面脚本直接绑定在按钮上,当按钮点击时就可以监听到,这种方法不太好很不灵活. void OnClick(){ Debug.Log("Button is Click!!!& ...

  3. 无约束优化方法(梯度法-牛顿法-BFGS- L-BFGS)

    本文讲解的是无约束优化中几个常见的基于梯度的方法,主要有梯度下降与牛顿方法.BFGS 与 L-BFGS 算法. 梯度下降法是基于目标函数梯度的,算法的收敛速度是线性的,并且当问题是病态时或者问题规模较 ...

  4. [分布式系统学习] 6.824 LEC3 GFS 笔记

    Google File System 第三课的准备是阅读论文GFS.该论文是分布式系统中经典论文之一. 读完做一点小总结. GFS的feature 1. 非POXIS接口API,支持对文件和文件夹的创 ...

  5. TOP100summit:【分享实录】链家网大数据平台体系构建历程

    本篇文章内容来自2016年TOP100summit 链家网大数据部资深研发架构师李小龙的案例分享. 编辑:Cynthia 李小龙:链家网大数据部资深研发架构师,负责大数据工具平台化相关的工作.专注于数 ...

  6. SHU 414 - 字符串进制转换

    题目链接:http://acmoj.shu.edu.cn/problem/414/ 很咸鱼的网上拉了个进制转换模板过来,因为数组开的太小一直WA,后来一气之下MAXN开到1e5,真是蓝瘦…… 后来实在 ...

  7. SQL Fundamentals: Using Single-Row Functions to Customize Output使用单行函数自定义输出

    SQL Fundamentals || Oracle SQL语言 DUAL is a public table that you can use to view results from functi ...

  8. CodeForces - 665D Simple Subset 想法题

    //题意:给你n个数(可能有重复),问你最多可以取出多少个数使得任意两个数之和为质数.//题解:以为是个C(2,n)复杂度,结果手摸几组,发现从奇偶性考虑,只有两种情况:有1,可以取出所有的1,并可以 ...

  9. hadoop完全分布式安装部署-笔记

    规划: [hadoop@db01 ~]$ cat /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4 ...

  10. 《SEO在网页制作中的应用》视频笔记

    学习了慕课网<SEO在网页制作中的应用>视频,今天将里面的知识整理一下. 一.SEO介绍 1.  搜索引擎工作原理 搜索引擎现在主流有百度.谷歌.360,他们都有庞大的搜索引擎数据库,每个 ...