题意:
按顺序给出线段, 上面的可能会覆盖下面的, 求出不被其他线段覆盖的所有线段
分析:暴力搜索,如果一条线段不被后面任一条覆盖,则它是答案之一
按顺序给出线段, 上面的可能会覆盖下面的, 求出不被其他线段覆盖的所有线段
分析:暴力搜索,如果一条线段不被后面任一条覆盖,则它是答案之一
重点:线段的平行,相交,点与线段的位置关系的判定, 点积叉积的灵活运用。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX 100005
#include <iostream>
#define PI acos(-1.0)
#define eps 1e-5
#define INF 1e8
using namespace std;
inline int sgn(double x){ return x < -eps ? -1 : ( x > eps ? 1 : 0) ;}
struct Point
{
double x, y;
Point(){}
Point(double xx, double yy):x(xx), y(yy){}
Point operator - (const Point &p)const{
return Point(x - p.x, y - p.y);
}
void input(){
cin>>x>>y;
}
void output(){
cout<<x<<y<<endl;
}
friend double det(const Point &p1, const Point &p2){
return p1.x * p2.y - p1.y * p2.x;
}
friend double dot(const Point &p1, const Point &p2){
return p1.x *p2.x + p1.y * p2.y;
}
friend Point operator * (const Point &p1, const double &w){
return Point(p1.x * w, p1.y * w);
}
friend Point operator / (const Point &p1, const double &w){
return Point(p1.x/ w, p1.y/ w);
}
};
struct Line
{
Point s, t;
Line(){}
Line(const Point &p1, const Point &p2):s(p1), t(p2){}
void input(){
s.input();
t.input();
}
bool isParell(const Line &line) const{
if(sgn( det(line.t - line.s, t - s) ) == 0 ){
return true;
}
return false;
}
bool InsectPoint(Point &res, const Line &line)const{
if(isParell(line))return false;
double s1 = det( t - s, line.s - s);
double s2 = det( t - s, line.t - s);
res = (line.t * s1 - line.s * s2) / (s1 - s2);
return true;
}
bool isOnLine(const Point &p1)const{//包括两端
return ( sgn( det(p1 - s, t - s) ) == 0 && sgn(dot(p1 - s, p1 - t) ) <= 0);
}
bool isInsect(const Line &line)const{
Point res;
if(!InsectPoint(res, line)){
// puts("parell");
return false;
}
// puts("not parell");
// res.output();
return (isOnLine(res) && line.isOnLine(res));
}
}line[MAX];
int main()
{
int n;
while(cin>>n, n){
for(int i = 0; i < n;i++){
line[i].input();
}
// cout<<line[0].isInsect(line[1])<<endl;
printf("Top sticks: ");
vector<int>ans;
for(int i = 0; i < n; i++){
bool isFind = true;
for(int j = i + 1; j < n; j++){
if(line[i].isInsect(line[j])){
isFind = false;
break;
}
}
if(isFind)ans.push_back(i + 1);
}
int tSize = ans.size();
for(int i = 0; i < tSize - 1; i++){
printf("%d, ", ans[i]);
}printf("%d.\n", ans[tSize - 1]);
}
return 0;
}