【BZOJ1007】[HNOI2008]水平可见直线【半平面交】
2016-05-18 15:32
453 查看
【题目链接】
学习一发计算几何基础。
/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef double DB;
const int maxn = 50005;
const DB eps = 1e-6;
struct _line {
DB k, b;
int id;
} l[maxn];
int n, sta[maxn], top;
inline bool cmp(_line x, _line y) {
return fabs(x.k - y.k) < eps ? x.b < y.b : x.k < y.k;
}
inline bool cmp2(int x, int y) {
return l[x].id < l[y].id;
}
inline DB cosp(_line x, _line y) {
return (x.b - y.b) / (y.k - x.k);
}
inline void insert(int id) {
while(top) {
if(fabs(l[sta[top]].k - l[id].k) < eps) top--;
else if(top > 1 && cosp(l[id], l[sta[top - 1]]) <= cosp(l[sta[top]], l[sta[top - 1]])) top--;
else break;
}
sta[++top] = id;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lf%lf", &l[i].k, &l[i].b), l[i].id = i;
sort(l + 1, l + 1 + n, cmp);
top = 0;
for(int i = 1; i <= n; i++) insert(i);
sort(sta + 1, sta + 1 + top, cmp2);
for(int i = 1; i <= top; i++) printf("%d ", l[sta[i]].id);
return 0;
}
学习一发计算几何基础。
/* Telekinetic Forest Guard */
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef double DB;
const int maxn = 50005;
const DB eps = 1e-6;
struct _line {
DB k, b;
int id;
} l[maxn];
int n, sta[maxn], top;
inline bool cmp(_line x, _line y) {
return fabs(x.k - y.k) < eps ? x.b < y.b : x.k < y.k;
}
inline bool cmp2(int x, int y) {
return l[x].id < l[y].id;
}
inline DB cosp(_line x, _line y) {
return (x.b - y.b) / (y.k - x.k);
}
inline void insert(int id) {
while(top) {
if(fabs(l[sta[top]].k - l[id].k) < eps) top--;
else if(top > 1 && cosp(l[id], l[sta[top - 1]]) <= cosp(l[sta[top]], l[sta[top - 1]])) top--;
else break;
}
sta[++top] = id;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%lf%lf", &l[i].k, &l[i].b), l[i].id = i;
sort(l + 1, l + 1 + n, cmp);
top = 0;
for(int i = 1; i <= n; i++) insert(i);
sort(sta + 1, sta + 1 + top, cmp2);
for(int i = 1; i <= top; i++) printf("%d ", l[sta[i]].id);
return 0;
}
相关文章推荐
- cp30连接池配置问题
- zoj3469——Food Delivery(区间dp)
- Java 多线程CountDownLatch、CyclicBarrier、Thread.join方法基本用法
- MKMapSnapshotOptions生成地图快照
- angularjs培训之filter
- HDU-3184-All Can Do【思维】
- 菜鸟成长记-Xcode开发必备快捷键操作
- Java中Arrays.asList的使用
- WPF 几种常用控件样式的总结
- 转: DH密钥交换和ECDH原理
- 转:基于TLS1.3的微信安全通信协议mmtls介绍
- leetcode Largest Rectangle in Histogram
- java设计模式分类
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- jquery uploadify+java
- 基于Android淡入淡出弹幕实现
- js中的prototype和基于prototype的继承总结
- Core Animation - 完成块
- IOS中的通知(NSNotifcation)
- jfinal 项目部署到jboss 步骤