题意:给你一个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(扫描线)的更多相关文章

  1. HDU 5831 Rikka with Parenthesis II(六花与括号II)

    31 Rikka with Parenthesis II (六花与括号II) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  2. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  3. hdu 4454 Stealing a Cake(三分之二)

    pid=4454" target="_blank" style="">题目链接:hdu 4454 Stealing a Cake 题目大意:给定 ...

  4. HDU 6091 - Rikka with Match | 2017 Multi-University Training Contest 5

    思路来自 某FXXL 不过复杂度咋算的.. /* HDU 6091 - Rikka with Match [ 树形DP ] | 2017 Multi-University Training Conte ...

  5. HDU 6088 - Rikka with Rock-paper-scissors | 2017 Multi-University Training Contest 5

    思路和任意模数FFT模板都来自 这里 看了一晚上那篇<再探快速傅里叶变换>还是懵得不行,可能水平还没到- - 只能先存个模板了,这题单模数NTT跑了5.9s,没敢写三模数NTT,可能姿势太 ...

  6. HDU 6093 - Rikka with Number | 2017 Multi-University Training Contest 5

    JAVA+大数搞了一遍- - 不是很麻烦- - /* HDU 6093 - Rikka with Number [ 进制转换,康托展开,大数 ] | 2017 Multi-University Tra ...

  7. HDU 6085 - Rikka with Candies | 2017 Multi-University Training Contest 5

    看了标程的压位,才知道压位也能很容易写- - /* HDU 6085 - Rikka with Candies [ 压位 ] | 2017 Multi-University Training Cont ...

  8. 【HDOJ6681】Rikka with Cake(扫描线,线段树)

    题意:给定一个n*m的平面,有k条垂直或平行的直线,问将平面分成了几个互不联通的部分 n,m<=1e9,k<=1e5 思路: 刻在DNA里的二维数点 #include<bits/st ...

  9. hdu多校第九场 1002 (hdu6681) Rikka with Cake 树状数组维护区间和/离散化

    题意: 在一块长方形蛋糕上切若干刀,每一刀都是从长方形某条边开始,垂直于这条边,但不切到对边,求把长方形切成了多少块. 题解: 块数=交点数+1 因为对于每个交点,唯一且不重复地对应着一块蛋糕. 就是 ...

随机推荐

  1. NIO基础操作

    原文链接http://zhhll.icu/2020/05/18/java%E5%9F%BA%E7%A1%80/IO/NIO%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C/ N ...

  2. java的重载与重写

    原文链接http://zhhll.icu/2020/11/11/java%E5%9F%BA%E7%A1%80/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1/%E9%87%8 ...

  3. 【函数分享】每日PHP函数分享(2021-1-12)

    str_pad() 使用另一个字符串填充字符串为指定长度 . string str_pad ( string $input, int $pad_length[, string $pad_string= ...

  4. Redis集群搭建与简单使用【转】

    Redis集群搭建与简单使用 安装环境与版本 用两台虚拟机模拟6个节点,一台机器3个节点,创建出3 master.3 salve 环境. redis 采用 redis-3.2.4 版本. 两台虚拟机都 ...

  5. 【SpringBoot1.x】SpringBoot1.x 入门

    SpringBoot1.x 入门 文章源码 简介 传统的 JavaEE 开发,十分笨重且配置繁琐,开发效率很低,而且有很复杂的部署流程,对于第三方技术的集成也很困难. Sring 全家桶时代则解决了上 ...

  6. LeetCode747 至少是其他数字两倍的最大数

    在一个给定的数组nums中,总是存在一个最大元素 . 查找数组中的最大元素是否至少是数组中每个其他数字的两倍. 如果是,则返回最大元素的索引,否则返回-1. 示例 1: 输入: nums = [3, ...

  7. centos 6.5 下安装RabbitMQ-3.7.28 二进制版本

    centos 6.5 下安装RabbitMQ-3.7.28 二进制版本 安装依赖: yum install -y ncurses-devel socat logrotatewxWidgets-deve ...

  8. Linux性能相关命令

    Linux性能相关命令 目录 Linux性能相关命令 1. 查看硬盘相关信息 2. 查看CPU相关信息 3. 查看内存相关信息 4. 查看进程运行的信息 1. 查看硬盘相关信息 cat /proc/s ...

  9. 九:APP及其他资产

    APP提取一键反编译提取 APP抓数据包进行工具配合 各种第三方应用相关探针技术 各种服务器接口相关探针技术 APP提取及抓包及后续配合 某APK一键提取反编译 利用burp历史抓更多URL 某IP无 ...

  10. Celery--短信与邮件

    1 Celery 实现短信--邮件 1.1 容联云-短信 from ronglian_sms_sdk import SmsSDK accountSid = '8a216da8757784cd01759 ...