ac1097
判断线段与直线的相交 这里有个地方需要注意的就是在 转换的时候容易报错 在叉积完后的判断符号的时候需要注意 这个地方会超出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的更多相关文章
随机推荐
- VIM 的一些技巧
vim配置文件 ~/.vimrc 如果没有自己创建一个即可 filetype plugin indent on #打开插件 set number #显示行号 syntax on #语法高亮 set c ...
- 【CF914G】Sum the Fibonacci 快速??变换模板
[CF914G]Sum the Fibonacci 题解:给你一个长度为n的数组s.定义五元组(a,b,c,d,e)是合法的当且仅当: 1. $1\le a,b,c,d,e\le n$2. $(s_a ...
- Android 使用MediaPlayer 播放 视频
http://pan.baidu.com/s/1lgKLS package cn.bgxt.surfaceviewdemo; import java.io.File; import android.m ...
- Edge Animate初篇教程(二)
Edge Animate 是Adobe最新出品的制作HTML5动画的可视化工具,简单的可以理解为HTML5版本的Flash Pro.在之后的文章中,我会逐一的介绍这款新的HTML5动画神器. 一.创建 ...
- Git - 忽略Xcode工程中UserInterfaceState.xcuserstate文件的问题
一.在同 .Git目录下创建.gitignore文件.在文件中加入如下内容: *.xcuserstate project.xcworkspace xcuserdata UserInterfaceSta ...
- hdu 1525 Euclid's Game【 博弈论】
Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtra ...
- CodeForces 551C - GukiZ hates Boxes - [二分+贪心]
题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...
- stress test - volume test
D:\wamp64\bin\mysql\mysql5.7.11\bin>mysqlslap --delimiter=";" --query=" INSERT I N ...
- Python实现简单HTTP服务器(一)
一.返回固定内容 # coding:utf-8 import socket from multiprocessing import Process def handle_client(client_s ...
- go语言编程入门
查看文档 首先先分享一个可以在本地就能查看文档的骚操作(linux系统) 1.打开命令行终端,输入godoc -http=:8000,如果想后台运行在后面加个& 2.然后打开浏览器,输入网址: ...