其实就是一道很简单的栈,只要明白什么情况会被挡住就行了。假如斜率一样则下面的被挡住,假如不一样就算交点,看那个交点在上面就行了。

题干:

Description
  在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为
可见的,否则Li为被覆盖的.
例如,对于直线:
L1:y=x; L2:y=-x; L3:y=
则L1和L2是可见的,L3是被覆盖的.
给出n条直线,表示成y=Ax+B的形式(|A|,|B|<=),且n条直线两两不重合.求出所有可见的直线.
Input
  第一行为N( < N < ),接下来的N行输入Ai,Bi
Output
  从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格
Sample Input - Sample Output

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
const db eps = 1e-;
struct node
{
db a,b;
int n;
}l[];
int n,top;
bool ans[];
node st[];
bool cmp(node a,node b)
{
if(fabs(a.a - b.a) < eps)
return a.b < b.b;
else
return a.a < b.a;
}
db crossx(node x1,node x2)
{
return (x2.b - x1.b) / (x1.a - x2.a);
}
void insert(node a)
{
while(top)
{
if(fabs(st[top].a - a.a) < eps)
top--;
else if(top > && crossx(a,st[top - ]) <= crossx(st[top],st[top - ]))
top--;
else
break;
}
st[++top] = a;
}
void work()
{
duke(i,,n)
insert(l[i]);
duke(i,,top)
{
ans[st[i].n] = ;
}
duke(i,,n)
if(ans[i] == )
printf("%d ",i);
}
int main()
{
read(n);
duke(i,,n)
{
scanf("%lf%lf",&l[i].a,&l[i].b);
l[i].n = i;
}
sort(l + ,l + n + ,cmp);
work();
return ;
}

最新文章

  1. PDO概念 分析 练习
  2. android 蓝牙 http://blog.csdn.net/u012843100/article/details/52384219
  3. PHP中的date()函数
  4. Dom4j解析xml
  5. 《我是一只IT小小鸟》读后感
  6. 总结列表显示ListView知识点
  7. OC学习笔记之属性详解和易错点
  8. 12天学好C语言——记录我的C语言学习之路(Day 7)
  9. iOS之Sqlite和FMDB
  10. hdu1198Farm Irrigation (DFS)
  11. HDU 3081 Marriage Match II(二分法+最大流量)
  12. 16_Python闭包
  13. 关于overflow的问题
  14. XX-NET史上最详细完整教程
  15. 转载 互斥体与互锁 &lt;第五篇&gt;
  16. kafka源代码环境配置
  17. kettle利用参数遍历执行指定目录下的所有对象
  18. 【laravel5.4】自定义404、503等页面
  19. 9、springboot之处理静态资源
  20. 【淘宝客】批量提取QQ号

热门文章

  1. 00The C Programming Language
  2. java基础学习日志--Stirng内存案例
  3. 洛谷——P4296 [AHOI2007]密码箱
  4. Luogu P1349 广义斐波那契数列
  5. [Algorithm] 7. Serialize and Deserialize Binary Tree
  6. Linux设置history命令显示行数以及时间
  7. python3爬虫-通过requests获取安居客房屋信息
  8. Python数据分析与展示(1)-数据分析之表示(2)-NumPy数据存取与函数
  9. airfoil polar data during post stall stages (high AOA)
  10. spring 学习(二)