#include <iostream> #include <algorithm> #include <cstdio> #include <vector> using namespace std; struct Node { int x,y; Node operator-(Node &node) { Node new_node; new_node.x=x-node.x; new_node.y=y-node.y; return new_node; } }; vector<vector<Node> > L; double cross(Node vec1,Node vec2) { return (double)vec1.x*vec2.y-(double)vec1.y*vec2.x; } bool straddle(Node n1,Node n2,Node n3,Node n4) { Node vec1=n2-n1; Node vec2=n3-n2; Node vec3=n4-n2; if(cross(vec1,vec2)*cross(vec1,vec3)<=0) return true; else return false; } double special_straddle(Node n1,Node n2,Node n3,Node n4) { Node vec1=n2-n1; Node vec2=n3-n2; Node vec3=n4-n2; return cross(vec1,vec2)*cross(vec1,vec3); } bool intersect(vector<vector<Node> > L) { int len=L.size(); for(int i=0;i<len-1;i++) { for(int m=0;m<L[i].size()-1;m++) { for(int j=i+1;j<len;j++) { for(int n=0;n<L[j].size()-1;n++) { if((m==0&&cross(L[j][n]-L[i][m],L[j][n]-L[j][n+1])==0)|| (m==L[i].size()-2&&cross(L[j][n]-L[i][m+1],L[j][n]-L[j][n+1])==0)|| (n==0&&cross(L[i][m]-L[j][n],L[i][m]-L[i][m+1])==0)|| (n==L[i].size()-2&&cross(L[i][m]-L[j][n+1],L[i][m]-L[i][m+1])==0)) continue; if(straddle(L[i][m],L[i][m+1],L[j][n],L[j][n+1])&& straddle(L[j][n],L[j][n+1],L[i][m],L[i][m+1])) return true; } } } } return false; } int main() { int num,n; //num为管道数,n为每条管道的端点数 vector<Node> p; while(scanf("%d",&num)!=EOF) { L.clear(); Node temp; for(int i=0;i<num;i++) { p.clear(); cin>>n; for(int j=0;j<n;j++) { cin>>temp.x>>temp.y; p.push_back(temp); } L.push_back(p); } if(num<=1) { cout<<"NO"<<endl; continue; } if(intersect(L)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
输入输出有问题,哎~
你想达到什么效果?
HDOJ上的题目总是Wrong,已经解决了,呵呵