bzoj4814: [Cqoi2017]小Q的草稿
Description
Input
Output
对每个点以它为中心进行扫描线,处理在右方的点和三角形。
#include<bits/stdc++.h>
typedef long long i64;
typedef double ld;
int n,m;
int sgn(i64 x){return x<?-:x>;}
struct pos{
int x,y;
void R(){scanf("%d%d",&x,&y);}
i64 pw2(){return i64(x)*x+i64(y)*y;}
}ps[],ws[],trs[][],O=(pos){,},now;
pos operator-(const pos&a,const pos&b){return (pos){a.x-b.x,a.y-b.y};}
int operator*(const pos&a,const pos&b){return sgn(i64(a.x)*b.y-i64(a.y)*b.x);}
ld mul(const pos&a,const pos&b){return ld(a.x)*b.y-ld(a.y)*b.x;}
bool cmp(const pos&a,const pos&b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator<(const pos&a,const pos&b){return a*b<;}
struct seg{
pos a[];
ld val()const{return mul(a[],a[])/mul(now,a[]-a[]);}
bool operator<(const seg&w)const{return val()<w.val();}
};
std::set<seg>st;
std::set<seg>::iterator its[];
struct Q{
pos a[];
int t,id;
bool operator<(const Q&w)const{
int x=a[t]*w.a[w.t];
return x?x<:t<w.t;
}
bool operator<(const pos&w){
int x=a[t]*w;
return x?x<:!t;
}
void cal(){
now=a[t];
if(cmp(now,O))now=(pos){,};
if(t)st.erase(its[id]);
else{
seg s=(seg){a[],a[]};
its[id]=st.insert(s).first;
}
}
}qs[];
bool cross(pos a,pos b1,pos b2){
pos ba=b2-a;
if((a*(b1-a))*(a*ba)>)return ;
pos b3=b1-b2;
return (b3*b2)*(b3*ba)<=;
}
int ans=,wp,qp,ip;
void scl(){
for(int i=,j=;i<wp;++i){
for(;j<qp&&qs[j]<ws[i];qs[j++].cal());
if(st.empty()||!cross(ws[i],st.begin()->a[],st.begin()->a[]))++ans;
}
}
void aq(pos a,pos b){
bool da=cmp(O,a),db=cmp(O,b);
++ip;
if(da)qs[qp++]=(Q){a,b,,ip};
else if(db)((Q){a,b,,ip}).cal();
if(db)qs[qp++]=(Q){a,b,,ip};
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)ps[i].R();
std::sort(ps+,ps+n+,cmp);
for(int i=;i<=m;++i)for(int j=;j<;++j)trs[i][j].R();
for(int i=;i<=n;++i){
st.clear();
wp=,qp=,ip=;
for(int j=i+;j<=n;++j)ws[wp++]=ps[j]-ps[i];
std::sort(ws,ws+wp);
for(int j=;j<=m;++j){
pos tr[];
for(int t=;t<;++t)tr[t]=trs[j][t]-ps[i];
std::sort(tr,tr+);
aq(tr[],tr[]);
}
std::sort(qs,qs+qp);
scl();
}
printf("%d\n",ans);
return ;
}
bzoj4814: [Cqoi2017]小Q的草稿的更多相关文章
- BZOJ 4814 Luogu P3699 [CQOI2017]小Q的草稿 (计算几何、扫描线、set)
题目链接 (BZOJ) http://lydsy.com/JudgeOnline/problem.php?id=4814 (Luogu) https://www.luogu.org/problem/P ...
- bzoj 4814: [Cqoi2017]小Q的草稿【计算几何】
//先打个50暴力,10min50分简直美滋滋~ #include<iostream> #include<cstdio> #include<algorithm> u ...
- bzoj 4813: [Cqoi2017]小Q的棋盘 [树形背包dp]
4813: [Cqoi2017]小Q的棋盘 题意: 某poj弱化版?树形背包 据说还可以贪心... #include <iostream> #include <cstdio> ...
- bzoj 4815: [Cqoi2017]小Q的表格 [数论]
4815: [Cqoi2017]小Q的表格 题意: 单点修改,查询前缀正方形和.修改后要求满足条件f(a,b)=f(b,a), b×f(a,a+b)=(a+b)*f(a,b) 一开始sb了认为一次只会 ...
- BZOJ_4813_[Cqoi2017]小Q的棋盘_dfs
BZOJ_4813_[Cqoi2017]小Q的棋盘_dfs Description 小Q正在设计一种棋类游戏.在小Q设计的游戏中,棋子可以放在棋盘上的格点中.某些格点之间有连线,棋子只能 在有连线的格 ...
- 【BZOJ4815】[CQOI2017]小Q的表格(莫比乌斯反演,分块)
[BZOJ4815][CQOI2017]小Q的表格(莫比乌斯反演,分块) 题面 BZOJ 洛谷 题解 神仙题啊. 首先\(f(a,b)=f(b,a)\)告诉我们矩阵只要算一半就好了. 接下来是\(b* ...
- 洛咕 P3700 [CQOI2017]小Q的表格
洛咕 P3700 [CQOI2017]小Q的表格 神仙题orz 首先推一下给的两个式子中的第二个 \(b\cdot F(a,a+b)=(a+b)\cdot F(a,b)\) 先简单的想,\(F(a,a ...
- 洛谷 P3698 [CQOI2017]小Q的棋盘 解题报告
P3698 [CQOI2017]小Q的棋盘 题目描述 小 Q 正在设计一种棋类游戏. 在小 Q 设计的游戏中,棋子可以放在棋盘上的格点中.某些格点之间有连线,棋子只能在有连线的格点之间移动.整个棋盘上 ...
- [BZOJ4813][CQOI2017]小Q的棋盘(DP,贪心)
4813: [Cqoi2017]小Q的棋盘 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 804 Solved: 441[Submit][Statu ...
随机推荐
- 软工实践——结对作业2【wordCount进阶需求】
附录: 队友的博客链接 本次作业的博客链接 同名仓库项目地址 一.具体分工 我负责撰写爬虫爬取信息以及代码整合测试,队友子恒负责写词组词频统计功能的代码. 二.PSP表格 PSP2.1 Persona ...
- Myelipse中xml约束文件的导入(以spring为例)
为了在电脑处于未联网状态下,beans.xml中书写标签具有提示功能,需要在电脑本地导入约束文件,下面上图 注意:将location后缀添加到key中beans的后面 注意:导入 context,ao ...
- JSP中页面向Action传递参数的几种方式
<form name="ThisForm" method="POST" action="index.jsp"> form是表单, ...
- web.xml配置Servlet出错(DispatcherServlet)
想当然的把servlet-mapping当成servlet的属性 后台也不报错,但是输入url,就是死活不执行那个servlet servlet和servlet-mapping是同一级的对象
- centos7.3使用花生壳映射端口
首先下载花生壳客户端(其实我觉得更应该叫做服务端),选择相应的版本就可,例如我就是选择的linux->centos版本的 https://hsk.oray.com/download/ 我的版本为 ...
- shell入门(二)——面试题实例
[~/shell]$ cat one.sh #!/bin/bash path=/root/shell/test.txt if [ ! -f $path ] //检测文件是否存在,如果不存在,把内容改为 ...
- 使用InternalsVisibleToAttribute给assembly添加“友元assembly”特性遭遇"强签名"
一.如何让Intenal成员暴露给另一个程序集 我们知道Modifier为Internal的类型成员仅限于当前程序集能够访问,但是在某些情况下,我们希望将它们暴露给另一个程序集.比较典型的应用场景包括 ...
- MySQL全文本搜索
启用全文本搜索支持 create table text( -> id int not null auto_increment, -> texts text null, -> prim ...
- 对HTML中的文字的修饰
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- sql server 附加只有mdf的数据库文件
有时候SQL Server意外断电会导致SQL Server的ldf日志文件丢失或者损坏,这个时候你如果直接附加mdf文件到SQL Server会失败,这里提供一个方法可以还原只有mdf的数据库文件, ...