题意:x轴上有n棵树,询问你站在某个点的视角。从左至右,单调队列(类似凸包)维护下。我强迫症地写了个模板QAQ

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define Rep(a, b) for(int a = 0; a < b; a++)
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {} typedef double db;
typedef long long LL;
typedef pair<int, int> pii;
typedef multiset<int> msi;
typedef multiset<int>::iterator msii;
typedef set<int> si;
typedef set<int>::iterator sii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {, -, , , -, , , -};
const int maxn = 1e5 + ;
const int maxm = 1e5 + ;
const int maxv = 1e7 + ;
const int MD = 1e9 +;
const int INF = 1e9 + ;
const double PI = acos(-1.0);
const double eps = 1e-; struct Point {
int x, y;
bool operator < (const Point &opt) const {
return x < opt.x || x == opt.x && y < opt.y;
}
double abs() {
return sqrt((double)x * x + (double)y * y);
}
Point operator - (const Point &opt) const {
return Point(x - opt.x, y - opt.y);
}
double operator * (const Point &opt) const {
return (double)x * opt.x + (double)y * opt.y;
}
constructInt2(Point, x, y);
void inp() {
scanf("%d %d", &x, &y);
}
void outp() {
printf("(%d, %d), ", x, y);
}
}; bool cmp(const pii &a, const pii &b) {
return a.first < b.first;
} double Cross(const Point &a, const Point &b) {
return (double)a.x * b.y - (double)a.y * b.x;
} template<class T> struct MonotoneQueue{
deque<T> Q;
MonotoneQueue<T>() { Q.clear(); }
T back() { return Q.back(); }
T back2() { if (Q.size() < ) return T(); return *(Q.end() - ); }
T front() { return Q.front(); }
void clear() { Q.clear(); }
bool empty() { return Q.empty(); }
void add_back(T x) { while (!empty() && !(back() - back2() < x - back2())) Q.pop_back(); Q.push_back(x); }
void pop_front() { Q.pop_front(); }
}; double toDegree(double x) { return x * 180.0 / PI; } Point p[maxn], L[maxn], R[maxn];
pii qry[maxn];
int n, m; struct Node {
Point dot;
bool operator < (const Node &a) const {
return Cross(dot, a.dot) < eps;
}
Node operator - (const Node &opt) const {
return Node(dot - opt.dot);
}
Node(Point dot = Point()): dot(dot) {}
};
MonotoneQueue<Node> DQ; void work(Point a[]) {
DQ.clear();
DQ.add_back(p[]);
int now = ;
for (int i = ; i < m; i++) {
while (now < n && p[now].x < qry[i].first) {
DQ.add_back(Node(p[now++]));
}
DQ.add_back(Node(Point(qry[i].first, )));
a[qry[i].second] = (DQ.back2() - DQ.back()).dot;
}
} int main() {
//freopen("in.txt", "r", stdin);
int T, cas = ;
cin >> T;
while (T--) {
cin >> n;
for (int i = ; i < n; i++) {
p[i].inp();
}
sort(p, p + n);
cin >> m;
for (int i = , x; i < m; i++) {
scanf("%d", &x);
qry[i] = make_pair(x, i);
}
sort(qry, qry + m, cmp); work(L); for (int i = ; i < n; i++) {
p[i].x = maxv - p[i].x;
}
sort(p, p + n);
for (int i = ; i < m; i++) {
qry[i].first = maxv - qry[i].first;
}
sort(qry, qry + m, cmp); work(R);
for (int i = ; i < m; i++) {
R[i].x = -R[i].x;
} printf("Case #%d:\n", ++cas);
for (int i = ; i < m; i++) {
printf("%.10f\n", toDegree(acos(L[i] * R[i] / L[i].abs() / R[i].abs())));
}
}
return ;
}

[hdu5033]单调队列的更多相关文章

  1. hdu5033 Building 单调队列

    // hdu5033 Building 单调队列 // // 题目大意: // // n栋大楼,有一个高度h和位置x.如今有一个人高度为0,有q个询问 // 每一个询问有一个位置x,求在位置x能看到天 ...

  2. BestCoder Round #89 B题---Fxx and game(单调队列)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5945     问题描述 输入描述 输出描述 输入样例 输出样例 题意:中文题,不再赘述: 思路:  B ...

  3. 单调队列 && 斜率优化dp 专题

    首先得讲一下单调队列,顾名思义,单调队列就是队列中的每个元素具有单调性,如果是单调递增队列,那么每个元素都是单调递增的,反正,亦然. 那么如何对单调队列进行操作呢? 是这样的:对于单调队列而言,队首和 ...

  4. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

  5. BZOJ 1047 二维单调队列

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 题意:见中文题面 思路:该题是求二维的子矩阵的最大值与最小值的差值尽量小.所以可以考 ...

  6. 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列

    第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...

  7. BZOJ1047: [HAOI2007]理想的正方形 [单调队列]

    1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2857  Solved: 1560[Submit][St ...

  8. hdu 3401 单调队列优化DP

    Trade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  9. 【转】单调队列优化DP

    转自 : http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列是一种严格单调的队列,可以单调递增,也可以单调递减.队 ...

随机推荐

  1. 6.表单提交,input键盘变搜索,有关自定义属性input操作

    1.键盘变搜索 1.) 在form 上加action="#", 2.)input type=search, 3.)此时会提交到 #,需要再添加一个input display=non ...

  2. python列表简介

    什么是列表?如何使用列表?https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range 列表相关知识: ...

  3. 负载均衡服务之HAProxy基础配置(一)

    前文我们聊了下haproxy的基础安装,以及怎样去代理后端主机的配置:当然没有很详细的去说配置文件中各指令的意思:有关haproxy的安装和代理后端server可以参考本人博客https://www. ...

  4. Apache jena SPARQL endpoint及推理

    一.Apache Jena简介 Apache Jena(后文简称Jena),是一个开源的Java语义网框架(open source Semantic Web Framework for Java),用 ...

  5. tensorflow1.0 变量加法

    import tensorflow as tf state = tf.Variable(0,name='counter') print(state.name) one = tf.constant(1) ...

  6. 算法笔记刷题5(PAT A1025)

    第一次上手PAT的甲级题目,瑟瑟发抖(英语不好对着题目愣了半天) 这一题的要点是使用sort函数. 使用sort函数必须使用 #include <algorithm> using name ...

  7. Go语言: 万物皆异步

    来源:https://www.jianshu.com/p/62c0cd107da3 同步和异步.阻塞和非阻塞 首先要明确的是,同步(Synchronous)和异步(Asynchronous),阻塞(B ...

  8. MySql --FIND_IN_SET() 函数 (转)

    例子:https://www.jianshu.com/p/b2c1ba0ba34f 举个例子来说:有个文章表里面有个type字段,他存储的是文章类型,有 1头条,2推荐,3热点,4图文 .....11 ...

  9. js事件冒泡于事件捕获

    事件冒泡 事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件. 事件冒泡是自下而上(从最深节点开始,向上传播事件)的触发事件 //例子 <div id="pa ...

  10. 关于XSS弹窗的小姿势

    最近快比赛了想刷刷题,做合天XSS进阶的时候遇到了过滤了alert然后还要弹窗效果的题目,这让我这个JS只学了一点点的菜鸡倍感无力.     在百度了其他资料后,发现confirm('xss')和pr ...