hdu 6681 Rikka with Cake(扫描线)
题意:给你一个n*m的的矩形框 现在又k条射线 问这个矩形框会被分为多少个区域
思路:之前的想法是枚举边界然后线段树扫一遍计算一下矩形个数 复杂度果断不行 后面发现其实答案就是交点数+1 然后就用线段树上下扫两边
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 1e5+7;
const int inf = 0x3f3f3f3f;
typedef long long ll;
const ll mod = 1e7+9;
struct tree{
int l,r,v;
};
tree t[N<<2];
struct node{
int x,y,z;
}up[N],down[N];
int xx[N];
bool cmp1(node a,node b){
return a.y<b.y; //升
}
bool cmp2(node a,node b){
return a.y>b.y; //降
}
void build(int p,int l,int r){
t[p].l=l; t[p].r=r; t[p].v=0;
if(l==r){
return ;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
t[p].v=t[p<<1].v+t[p<<1|1].v; }
void update(int p,int x,int v){
if(t[p].l==t[p].r&&t[p].l==x){
t[p].v+=v;
return ;
}
int mid=(t[p].l+t[p].r)>>1;
if(x<=mid) update(p<<1,x,v);
else update(p<<1|1,x,v);
t[p].v=t[p<<1].v+t[p<<1|1].v;
}
ll query(int p,int l,int r){
if(l<=t[p].l&&t[p].r<=r){
return t[p].v;
}
int mid=(t[p].l+t[p].r)>>1;
ll res=0;
if(l<=mid) res+=query(p<<1,l,r);
if(r>mid) res+=query(p<<1|1,l,r);
return res;
}
int getpo(int x,int n){
int po=lower_bound(xx,xx+n,x)-xx+1;
return po;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin>>t;
while(t--){
int n,m,k; cin>>n>>m>>k;
int cnt=0; int cntup=0; int cntdown=0;
xx[cnt++]=1; xx[cnt++]=n-1;
for(int i=1;i<=k;i++){
int x,y; char ty;
cin>>x>>y>>ty;
xx[cnt++]=x;
if(ty=='U'){
up[cntup++]=node{x,y,1};
}else if(ty=='D'){
down[cntdown++]=node{x,y,1};
}else if(ty=='L'){
up[cntup++]=node{x,y,0};
down[cntdown++]=node{x,y,0};
}else{
up[cntup++]=node{x,y,3};
down[cntdown++]=node{x,y,3};
}
}
sort(xx,xx+cnt);
cnt=unique(xx,xx+cnt)-xx;
sort(up,up+cntup,cmp1);
sort(down,down+cntdown,cmp2);
build(1,1,cnt);
ll ans=1;
for(int i=0;i<cntup;i++){
if(up[i].z==1){
int po=getpo(up[i].x,cnt);
update(1,po,1);
}else if(up[i].z==0){
int l=getpo(1,cnt); int r=getpo(up[i].x,cnt);
ans+=query(1,l,r);
}else{
int l=getpo(up[i].x,cnt); int r=getpo(n-1,cnt);
ans+=query(1,l,r);
}
}
build(1,1,cnt);
for(int i=0;i<cntdown;i++){
if(down[i].z==1){
int po=getpo(down[i].x,cnt);
update(1,po,1);
}else if(down[i].z==0){
int l=getpo(1,cnt); int r=getpo(down[i].x,cnt);
ans+=query(1,l,r);
}else{
int l=getpo(down[i].x,cnt); int r=getpo(n-1,cnt);
ans+=query(1,l,r);
}
}
cout<<ans<<endl;
}
}
hdu 6681 Rikka with Cake(扫描线)的更多相关文章
- HDU 5831 Rikka with Parenthesis II(六花与括号II)
31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- hdu 4454 Stealing a Cake(三分之二)
pid=4454" target="_blank" style="">题目链接:hdu 4454 Stealing a Cake 题目大意:给定 ...
- HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5
思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...
- HDU 6088 - Rikka with Rock-paper-scissors | 2017 Multi-University Training Contest 5
思路和任意模数FFT模板都来自 这里 看了一晚上那篇<再探快速傅里叶变换>还是懵得不行,可能水平还没到- - 只能先存个模板了,这题单模数NTT跑了5.9s,没敢写三模数NTT,可能姿势太 ...
- HDU 6093 - Rikka with Number | 2017 Multi-University Training Contest 5
JAVA+大数搞了一遍- - 不是很麻烦- - /* HDU 6093 - Rikka with Number [ 进制转换,康托展开,大数 ] | 2017 Multi-University Tra ...
- HDU 6085 - Rikka with Candies | 2017 Multi-University Training Contest 5
看了标程的压位,才知道压位也能很容易写- - /* HDU 6085 - Rikka with Candies [ 压位 ] | 2017 Multi-University Training Cont ...
- 【HDOJ6681】Rikka with Cake(扫描线,线段树)
题意:给定一个n*m的平面,有k条垂直或平行的直线,问将平面分成了几个互不联通的部分 n,m<=1e9,k<=1e5 思路: 刻在DNA里的二维数点 #include<bits/st ...
- hdu多校第九场 1002 (hdu6681) Rikka with Cake 树状数组维护区间和/离散化
题意: 在一块长方形蛋糕上切若干刀,每一刀都是从长方形某条边开始,垂直于这条边,但不切到对边,求把长方形切成了多少块. 题解: 块数=交点数+1 因为对于每个交点,唯一且不重复地对应着一块蛋糕. 就是 ...
随机推荐
- 【函数分享】每日PHP函数分享(2021-1-11)
str_shuffle() 随机打乱一个字符串. string str_shuffle ( string $str ) 参数描述 str 输入字符串.返回值:返回打乱后的字符串.实例: < ...
- 当音乐学博士搞起编程,用一本书改变了Java世界!
前言 说到Spring,也许现在的开发者们最先想到的是 Josh Long 超快的语速与现场代码能力,让很多Java开发者折服. 然后Spring的历史上,最传奇的还是要数其创始人:Rod Johns ...
- 【SpringBoot1.x】SpringBoot1.x Web 开发
SpringBoot1.x Web 开发 文章源码 简介 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty 或 Undertow 轻松创建独立的 HTTP ...
- 详解 TCP的三次握手四次挥手
本文转载来自https://blog.csdn.net/qzcsu/article/details/72861891 背景描述 通过上一篇中网络模型中的IP层的介绍,我们知道网络层,可以实现两个主机之 ...
- 八:架构,搭建,WAF
WAF防护分析 什么是WAF应用 如何快速识别WAF 识别WAF对于安全测试的意义 CMS识别技术 源码获取技术 架构信息获取 站点搭建分析 搭建习惯-目录型站点 sti.blcu-bbs 目录型站点 ...
- 【Linux】ssh设置了密钥,但ssh登陆的时候还需要输入密码
------------------------------------------------------------------------------------------------- | ...
- 解决ROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat table study_record( id int(11) not null
之前一直用的好好的,突然就出现了这个错误: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual tha ...
- mysql:如何解决数据修改冲突(事务+行级锁的实际运用)
摘要:最近做一个接诊需求遇到一个问题,假设一个订单咨询超过3次就不能再接诊,但如果两个医生同时对该订单进行咨询,查数据库的时候查到的接诊次数都是2次,那两个医生都能接诊,所谓接诊可以理解为更新了接诊次 ...
- missing tables and indexes的处理办法
最近做了SAP系统的异构迁移,顺便把oracle DB也升级了,从10g升级到11g,但是升级后,在DB02或者是ora_space中的diagnostics->Missing Tables a ...
- 获取html中某些标签的值
一.获取单选按钮radio的值 <!doctype html> <html lang="en"> <head> <meta charset ...