标签:des style blog http color os strong io
http://poj.org/problem?id=2653
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 9531 | Accepted: 3517 |
Description
Input
Output
Sample Input
5 1 1 4 2 2 3 3 1 1 -2.0 8 4 1 4 8 2 3 3 6 -2.0 3 0 0 1 1 1 0 2 1 2 0 3 1 0
Sample Output
Top sticks: 2, 4, 5. Top sticks: 1, 2, 3.
Hint
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <stdlib.h> #include <math.h> #include <algorithm> using namespace std; #define MAXX 100010 #define eps 1e-6 typedef struct point { double x,y; }point; typedef struct { point st,ed; }line; bool xy(double x,double y){ return x<y-eps; } bool dy(double x,double y){ return x>y+eps; } bool xyd(double x,double y){ return x<y+eps; } bool dyd(double x,double y){ return x>y-eps; } bool dd(double x,double y){ return fabs(x-y)<eps; } double crossProduct(point a,point b,point c) { return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); } bool onSegment(point a,point b,point c) { double maxx=max(a.x,b.x); double maxy=max(a.y,b.y); double minx=min(a.x,b.x); double miny=min(a.y,b.y); if(dd(crossProduct(a,b,c),0.0)&&dyd(c.x,minx) &&xyd(c.x,maxx)&&dyd(c.y,miny)&&xyd(c.y,maxy)) return true; return false; } bool segIntersect(point p1,point p2,point p3,point p4) { double d1=crossProduct(p3,p4,p1); double d2=crossProduct(p3,p4,p2); double d3=crossProduct(p1,p2,p3); double d4=crossProduct(p1,p2,p4); if(xy(d1*d2,0.0)&&xy(d3*d4,0.0)) return true; if(dd(d1,0.0)&&onSegment(p3,p4,p1)) return true; if(dd(d2,0.0)&&onSegment(p3,p4,p2)) return true; if(dd(d3,0.0)&&onSegment(p1,p2,p3)) return true; if(dd(d4,0.0)&&onSegment(p1,p2,p4)) return true; return false; } point p[MAXX]; line li[MAXX]; int num[MAXX]; int main() { int m,n,i,j; while(scanf("%d",&n)!=EOF&&n) { memset(num,0,sizeof(num)); for(i=0;i<n;i++) { scanf("%lf%lf%lf%lf",&li[i].st.x,&li[i].st.y,&li[i].ed.x,&li[i].ed.y); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(segIntersect(li[i].st,li[i].ed,li[j].st,li[j].ed)) { num[i]++; break; } } } int cas=0,tes=0,tmp; //int str[MAXX]; for(i=0;i<n;i++) { if(num[i] == 0) { cas++; } } printf("Top sticks: "); for(i=0;i<n;i++) { if(num[i] == 0 && tes<cas-1) { printf("%d, ",i+1); tes++; tmp=i; } }//printf("%d**",i); for(j=tmp+1;j<n;j++) { if(num[j] == 0) { printf("%d.\n",j+1); } } } return 0; }
poj 2653 (线段相交判断),布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://www.cnblogs.com/ccccnzb/p/3879192.html