poj 2653 Pick-up sticks
来源:互联网 发布:淘宝客服售后面试问题 编辑:程序博客网 时间:2024/05/19 22:45
题意:
按顺序给出线段, 上面的可能会覆盖下面的, 求出不被其他线段覆盖的所有线段
分析:暴力搜索,如果一条线段不被后面任一条覆盖,则它是答案之一
按顺序给出线段, 上面的可能会覆盖下面的, 求出不被其他线段覆盖的所有线段
分析:暴力搜索,如果一条线段不被后面任一条覆盖,则它是答案之一
重点:线段的平行,相交,点与线段的位置关系的判定, 点积叉积的灵活运用。
#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 1e8using 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;}
- POJ 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- poj 2653 Pick-up sticks
- POJ 2653 Pick-up sticks
- ORACLE 11G RAC ASM磁盘全部丢失后的恢复
- 自制X86操作系统(1)-系统引导篇3(保护模式)
- experiment : 用OD下消息断点, 捕获按钮操作.
- 单车到飞船
- button1 cannot be resolved or is not a field
- poj 2653 Pick-up sticks
- Hardcoded string "Button", should use @string resource
- MySQL的concat,concat_ws,group_concat
- VMware vSphere 服务器虚拟化之二十三 桌面虚拟化之创建手动虚拟桌面池
- 【解决办法】ubuntu server 版的 ISO文件,在 Ultra ISO 打开,内容不对,写入到 启动U盘,也不能引导系统
- IOS随笔
- 12 Amazing and Essential Linux Books To Enrich Your Brain and Library
- 软件定义网络的学习笔记--第一篇
- CareerCup 4.8