【LOJ】#2549. 「JSOI2018」战争
题解
仔细分析了一下,如果写个凸包+每次暴力半平面交可以得到70分,正解有点懵啊
然后用到了一个非常结论,但是大概出题人觉得江苏神仙一个个都可以手证的结论吧。。
Minkowski sum
两个凸包分别为\(A,B\),向量为\(\vec{v}\)
\(B + \vec{v} = A\)
那么可以得到\(\vec{v} = A - B\)
也就是第一个凸包,和第二个凸包取反,这些向量的集合两两组合能达到向量的组合
求法就是,我们找到两个凸包右下角的点,取这些凸包上的边的向量,转一圈即可,具体可以看代码。。
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct Point {
db x,y;
Point(db _x = 0.0,db _y = 0.0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,const db &d) {
return Point(a.x * d,a.y * d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return x * x + y * y;
}
}A[MAXN],B[MAXN],C[MAXN * 2],sta[MAXN * 2],S,va[MAXN],vb[MAXN];
int N,M,top,tot,Q;
bool cmp(Point a,Point b) {
db d = (a - S) * (b - S);
if(d == 0.0) {return (a - S).norm() < (b - S).norm();}
else return d > 0;
}
int Convex(int n,Point *p) {
for(int i = 2 ; i <= n ; ++i) {
if(p[i].x < p[1].x || (p[i].x == p[1].x && p[i].y < p[1].y)) swap(p[1],p[i]);
}
S = p[1];
sort(p + 2,p + n + 1,cmp);
top = 0;
for(int i = 1 ; i <= n ; ++i) {
while(top >= 2 && (p[i] - sta[top - 1]) * (sta[top] - sta[top - 1]) >= 0) --top;
sta[++top] = p[i];
}
n = top;
for(int i = 1 ; i <= n ; ++i) p[i] = sta[i];
return n;
}
void Process() {
tot = 0;
for(int i = 1 ; i < N ; ++i) {
va[i] = A[i + 1] - A[i];
}
for(int i = 1 ; i < M ; ++i) {
vb[i] = B[i + 1] - B[i];
}
va[N] = A[1] - A[N];
vb[M] = B[1] - B[M];
int al = 1,bl = 1; C[++tot] = A[1] + B[1];
while(al <= N && bl <= M) {
if(va[al] * vb[bl] >= 0) {
C[tot + 1] = C[tot] + va[al++];
}
else {
C[tot + 1] = C[tot] + vb[bl++];
}
++tot;
}
while(al <= N) {C[tot + 1] = C[tot] + va[al++];++tot;}
while(bl <= M) {C[tot + 1] = C[tot] + vb[bl++];++tot;}
}
bool Find(Point p) {
if(p * (C[2] - C[1]) > 0 || (C[tot] - C[1]) * p > 0) return false;
if(p * (C[2] - C[1]) == 0.0) {
if(p.norm() <= (C[2] - C[1]).norm()) return true;
return false;
}
int L = 2,R = tot - 1;
while(L < R) {
int mid = (L + R + 1) >> 1;
if((C[mid] - C[1]) * p > 0) L = mid;
else R = mid - 1;
}
return (C[L] - C[1]) * p + p * (C[L + 1] - C[1]) <= (C[L] - C[1]) * (C[L + 1] - C[1]);
}
void Solve() {
read(N);read(M);read(Q);
int x,y;
for(int i = 1 ; i <= N ; ++i) {
read(x);read(y);A[i] = Point(x,y);
}
for(int i = 1 ; i <= M ; ++i) {
read(x);read(y);B[i] = Point(-x,-y);
}
N = Convex(N,A);M = Convex(M,B);
Process();tot = Convex(tot,C);
Point d;
for(int i = 1 ; i <= Q ; ++i) {
read(x);read(y);
d = Point(x,y);
if(Find(d - C[1])) {puts("1");}
else puts("0");
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
【LOJ】#2549. 「JSOI2018」战争的更多相关文章
- 「JSOI2018」战争
「JSOI2018」战争 解题思路 我们需要每次求给一个凸包加上一个向量后是否与另外一个凸包相交,也就是说是否存在 \[ b\in B,(b+w)\in A \] 这里 \(A, B\) 表示凸包内部 ...
- LOJ 2550 「JSOI2018」机器人——找规律+DP
题目:https://loj.ac/problem/2550 只会写20分的搜索…… #include<cstdio> #include<cstring> #include&l ...
- LOJ 2548 「JSOI2018」绝地反击 ——二分图匹配+网络流手动退流
题目:https://loj.ac/problem/2548 如果知道正多边形的顶点,就是二分答案.二分图匹配.于是写了个暴力枚举多边形顶点的,还很愚蠢地把第一个顶点枚举到 2*pi ,其实只要 \( ...
- LOJ 2551 「JSOI2018」列队——主席树+二分
题目:https://loj.ac/problem/2551 答案是排序后依次走到 K ~ K+r-l . 想维护一个区间排序后的结果,使得可以在上面二分.求和:二分可以知道贡献是正还是负. 于是想用 ...
- LOJ 2547 「JSOI2018」防御网络——思路+环DP
题目:https://loj.ac/problem/2547 一条树边 cr->v 会被计算 ( n-siz[v] ) * siz[v] 次.一条环边会被计算几次呢?于是去写了斯坦纳树. #in ...
- LOJ 2546 「JSOI2018」潜入行动——树形DP
题目:https://loj.ac/problem/2546 dp[ i ][ j ][ 0/1 ][ 0/1 ] 表示 i 子树,用 j 个点,是否用 i , i 是否被覆盖. 注意 s1<= ...
- Loj #3089. 「BJOI2019」奥术神杖
Loj #3089. 「BJOI2019」奥术神杖 题目描述 Bezorath 大陆抵抗地灾军团入侵的战争进入了僵持的阶段,世世代代生活在 Bezorath 这片大陆的精灵们开始寻找远古时代诸神遗留的 ...
- Loj #2192. 「SHOI2014」概率充电器
Loj #2192. 「SHOI2014」概率充电器 题目描述 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品--概率充电器: 「采用全新纳米级加工技术,实现元件与导线能否通电完 ...
- Loj #3096. 「SNOI2019」数论
Loj #3096. 「SNOI2019」数论 题目描述 给出正整数 \(P, Q, T\),大小为 \(n\) 的整数集 \(A\) 和大小为 \(m\) 的整数集 \(B\),请你求出: \[ \ ...
随机推荐
- 【hdu3842】 Machine Works
http://acm.hdu.edu.cn/showproblem.php?pid=3842 (题目链接) 题意 一个公司使用一个厂房$D$天,希望获利最大.有$n$台机器,每一台可以在第$D_i$天 ...
- react入门-props.children
在ReactDOM.render里面我们写我们的自定义组件的时候有时需要加一下子元素进去: <!DOCTYPE html> <html lang="en"> ...
- Java基础-SSM之mybatis一对一外键关联
Java基础-SSM之mybatis一对一外键关联 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.准备测试环境(创建数据库表) 1>.创建husbandsfk和wife ...
- cookie添加删除修改
//cookie添加 document.cookie="username=John Doe"; //添加过期时间 document.cookie="username1=J ...
- 关于 xcode5 的no matching provisioning profiles found
CHENYILONG Blog 关于 xcode5 的no matching provisioning prof- about the question in xcode5 "no matc ...
- 第12月第29天 cocos quick manual
1. Example: $ cd cocos2d-x $ ./setup.py $ source FILE_TO_SAVE_SYSTEM_VARIABLE $ cocos new MyGame -p ...
- [译]How To Use the Linux Auditing System on CentOS 7
本文是How To Use the Linux Auditing System on CentOS 7的中文版,翻译不到之处,还请指出和多多包涵.本文并不会完全遵从原文的一些格式,而是加入自己学习的理 ...
- 2016最新的中国省市区三级数据库表.sql mssql
/****** Object: Table [dbo].[t_Area] Script Date: 09/10/2016 09:35:46 ******/ SET ANSI_NULLS ON GO S ...
- C++ 螺旋矩阵算法
清理磁盘空间的时候翻出了多年前写过的螺旋矩阵,代码效率和水平较低,纪念一下,保存到博客园! // ConsoleApplication3.cpp : 定义控制台应用程序的入口点. // #includ ...
- apache虚拟主机配置及常用安全配置
环境准备: 服务器系统:CentOS 6.5 安装lamp环境: yum -y install mysql mysql-server php php-mysql httpd php-gd* freet ...