跳到主要內容

uva 866

此題用模板即可,因為不會有連到端點的線,所以也就不會有剛好三條線相交在同一點的情況

/*
* GCA : "Computer is artificial subject absolutely,Math is God"
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cctype>
#include <utility>
#include <ctime>
using namespace std;
#ifdef DEBUG
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...) printf("DEBUG: "),printf(__VA_ARGS__)
#else
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...)
#endif
typedef unsigned int uint;
typedef long long int Int;
typedef unsigned long long int UInt;
#define Set(a,s) memset(a,s,sizeof(a))
#define Pln() printf("\n")
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define M 100005
#define PB push_back
#define oo INT_MAX
#define FOR(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)
#define eps 1e-9
#define X first
#define Y second
inline bool xdy(double x,double y){return x>y+eps;}
inline bool xddy(double x,double y){return x>y-eps;}
inline bool xcy(double x,double y){return x<y-eps;}
inline bool xcdy(double x,double y){return x<y+eps;}
const Int mod=1000000007;
struct point {
double x, y;
};
struct line {
point a, b;
};
#define zero(x) (((x)>0?(x):-(x))<eps)
double xmult(point p1, point p2, point p0) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
double xmult(double x1, double y1, double x2, double y2, double x0, double y0) {
return (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);
}
int same_side(point p1, point p2, line l) {
return xmult(l.a, p1, l.b) * xmult(l.a, p2, l.b) > eps;
}
int same_side(point p1, point p2, point l1, point l2) {
return xmult(l1, p1, l2) * xmult(l1, p2, l2) > eps;
}
int opposite_side(point p1, point p2, line l) {
return xmult(l.a, p1, l.b) * xmult(l.a, p2, l.b) < -eps;
}
int opposite_side(point p1, point p2, point l1, point l2) {
return xmult(l1, p1, l2) * xmult(l1, p2, l2) < -eps;
}
int dots_inline(point p1, point p2, point p3) {
return zero(xmult(p1, p2, p3));
}
int dots_inline(double x1, double y1, double x2, double y2, double x3,
double y3) {
return zero(xmult(x1, y1, x2, y2, x3, y3));
}
//判斷點是否在線段上,包括端點
int dot_online_in(point p, line l) {
return zero(xmult(p, l.a, l.b)) && (l.a.x - p.x) * (l.b.x - p.x) < eps
&& (l.a.y - p.y) * (l.b.y - p.y) < eps;
}
int dot_online_in(point p, point l1, point l2) {
return zero(xmult(p, l1, l2)) && (l1.x - p.x) * (l2.x - p.x) < eps
&& (l1.y - p.y) * (l2.y - p.y) < eps;
}
int intersect_in(line u, line v) {
if (!dots_inline(u.a, u.b, v.a) || !dots_inline(u.a, u.b, v.b))
return !same_side(u.a, u.b, v) && !same_side(v.a, v.b, u);
return dot_online_in(u.a, v) || dot_online_in(u.b, v)
|| dot_online_in(v.a, u) || dot_online_in(v.b, u);
}
int intersect_in(point u1, point u2, point v1, point v2) {
if (!dots_inline(u1, u2, v1) || !dots_inline(u1, u2, v2))
return !same_side(u1, u2, v1, v2) && !same_side(v1, v2, u1, u2);
return dot_online_in(u1, v1, v2) || dot_online_in(u2, v1, v2)
|| dot_online_in(v1, u1, u2) || dot_online_in(v2, u1, u2);
}
int intersect_ex(line u, line v) {
return opposite_side(u.a, u.b, v) && opposite_side(v.a, v.b, u);
}
int intersect_ex(point u1, point u2, point v1, point v2) {
return opposite_side(u1, u2, v1, v2) && opposite_side(v1, v2, u1, u2);
}
int n;
line lines[M];
int real[M];
int main() {
ios_base::sync_with_stdio(0);
int test;
scanf("%d",&test);
while(test--){
int realnum=0;
Set(real,0);
scanf("%d",&n);
double ux,uy,vx,vy;
for(int i=0;i<n;i++){
scanf("%lf%lf%lf%lf",&ux,&uy,&vx,&vy);
lines[i].a.x=ux;
lines[i].a.y=uy;
lines[i].b.x=vx;
lines[i].b.y=vy;
}
int ans=0;
for(int i=0;i<n;i++){
int now=1;
for(int j=0;j<n;j++){
if(i==j)continue;
if(intersect_ex(lines[i],lines[j])){
now++;
}
}
ans+=now;
}
printf("%d\n",ans);
if(test)Pln();
}
















}

留言