判断线段与直线的相交  这里有个地方需要注意的就是在 转换的时候容易报错 在叉积完后的判断符号的时候需要注意 这个地方会超出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. Apache 的mod_auth_cas模块的介绍和使用

    apache的mod_auth_cas模块是一个集成到apache中的cas客户端,一般是配合Apache的反向代理来使用,对某个url的请求先经过apache,apache会判断是否经过cas认证, ...

  2. jenkins - svn: E170001报错的原因以及解决方案

    1. 什么问题What? 使用Jenkins配置的svn拉取项目,Jenkins报错:svn: E170001; Your credentials to connect to the reposito ...

  3. SDK Location not found Android Studio + Gradle

    extends: http://stackoverflow.com/questions/19272127/sdk-location-not-found-android-studio-gradle I ...

  4. java 内存深度解析

    java 中的包括以下几大种的内存区域:1.寄存器    2.stack(栈) 3.heap(堆) 4.数据段 5.常量池 那么相应的内存区域中又存放什么东西(主要介绍 stack heap)? 栈: ...

  5. 2018牛客网暑期ACM多校训练营(第一场) D - Two Graphs - [无向图同构]

    题目链接:https://www.nowcoder.com/acm/contest/139/D 题目描述 Two undirected simple graphs  and  where  are i ...

  6. UNSIGNED command-line client

    High Performance MySQL, Third Edition by Baron Schwartz, Peter Zaitsev, and Vadim Tkachenko   There ...

  7. http://www.cnblogs.com/linxiyue/p/8244724.html

    http://www.cnblogs.com/linxiyue/p/8244724.html

  8. (四)Web应用开发---新增对象Master类别

    UI设计类似如下形式 Copy如下Html代码到新创建的Html <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xh ...

  9. 第五课 JAVA反射获取对象属性和方法(通过配置文件)

    Service1.java package reflection; public class Service1 { public void doService1(){ System.out.print ...

  10. 常用python包(依赖)Ubuntu下

    amqp==1.4.9anyjson==0.3.3apturl==0.5.2beautifulsoup4==4.4.1billiard==3.3.0.23blinker==1.3Brlapi==0.6 ...