AC日记——玻璃切割 51nod 1562
思路:
并查集;
离线操作;
先把每次切割都存下来;
然后从后面不断合并切割;
然后每次更新最大长和宽;
记录答案;
要开longlong;
来,上代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 400005
#define ll long long struct OperType {
ll l,r,x;
};
struct OperType hh[maxn],ww[maxn]; struct CutType {
ll x,id;
};
struct CutType qh[maxn],qw[maxn]; ll f1[maxn],f2[maxn],w,h,n,totw,toth,dis1[maxn],dis2[maxn];
ll answ,ansh,ans[maxn]; bool ty[maxn]; inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} ll find1(ll x)
{
if(f1[x]==x) return f1[x];
f1[x]=find1(f1[x]);
return f1[x];
} ll find2(ll x)
{
if(f2[x]==x) return f2[x];
f2[x]=find2(f2[x]);
return f2[x];
} bool cmp(CutType aa,CutType bb)
{
return aa.x<bb.x;
} int main()
{
in(w),in(h),in(n);char ch[];
for(ll i=;i<=n;i++)
{
scanf("%s",ch);
if(ch[]=='H')
{
ty[i]=true;
in(hh[++toth].x);
qh[toth].x=hh[toth].x;
qh[toth].id=toth,f1[toth]=toth;
}
else
{
in(ww[++totw].x);
qw[totw].x=ww[totw].x;
qw[totw].id=totw,f2[totw]=totw;
}
}
sort(qw+,qw+totw+,cmp);
sort(qh+,qh+toth+,cmp);
ll pos=;f1[toth+]=toth+,f2[totw+]=totw+;
for(ll i=;i<=toth;i++)
{
dis1[i]=qh[i].x-pos,pos=qh[i].x,ansh=max(dis1[i],ansh);
hh[qh[i].id].l=i,hh[qh[i].id].r=i+;
}
dis1[toth+]=h-pos,ansh=max(ansh,dis1[toth+]),pos=;
for(ll i=;i<=totw;i++)
{
dis2[i]=qw[i].x-pos,pos=qw[i].x,answ=max(dis2[i],answ);
ww[qw[i].id].l=i,ww[qw[i].id].r=i+;
}
dis2[totw+]=w-pos,answ=max(answ,dis2[totw+]);
ans[n]=answ*ansh;
for(ll i=n;i>;i--)
{
if(ty[i])
{
ll x=find1(hh[toth].l),y=find1(hh[toth].r);
if(x!=y)
{
dis1[x]+=dis1[y],f1[y]=x;
ansh=max(ansh,dis1[x]);
}
toth--;
}
else
{
ll x=find2(ww[totw].l),y=find2(ww[totw].r);
if(x!=y)
{
dis2[x]+=dis2[y],f2[y]=x;
answ=max(answ,dis2[x]);
}
totw--;
}
ans[i-]=answ*ansh;
}
for(ll i=;i<=n;i++) printf("%lld\n",ans[i]);
return ;
}
AC日记——玻璃切割 51nod 1562的更多相关文章
- AC日记——最高奖励 51nod 1163
最高的奖励 思路: 排序: 时间为第一关键字,按总小到大排: 价值为第二关键字,按从大到小排: 然后,不难看出,如果两个时间不同: 那么,两个时间之间最少能做一件事: 因为他们的时间下限最少相差1: ...
- AC日记——幸运号码 51nod 1043
幸运号码 思路: 传说中的数位dp: 不难发现,n(n<1000) ,那么,n个数的最大和为9*1000=9000: 对于9000*1000的时间范围,我们可以用dp来解决: dp[i][j], ...
- AC日记——石子归并 51nod 1021
石子归并 思路: 经典动态规划——归并类问题: 我们把状态划为n个,即1-n的n个长度为n个状态: 那么,每个长度为i的状态都可以由i-1个长度为i-1的状态推出: 所以,dp转移方程: dp[i][ ...
- AC日记——背包问题 V2 51nod 1086
有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi ...
- 51nod 1562 玻璃切割
1562 玻璃切割 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1562 题目来源: CodeForces 基准时间 ...
- 51nod 1562 玻璃切割 (STL map+一点点的思考)
1562 玻璃切割 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 现在有一块玻璃,是长方形的(w 毫米× h 毫米),现在要 ...
- AC日记——codevs1688求逆序对
AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...
- 51nod 1562 玻璃切割 (set)
#include<stdio.h> #include<iostream> #include<set> using namespace std; typedef lo ...
- AC日记——最小正子段和 51nod 1065
最小正子段和 思路: 找最小的大于0的sum[j]-sum[i](j>i): 高级数据结构(splay)水过: 来,上代码: #include <cstdio> #include & ...
随机推荐
- 修改window 10 开始菜单问题
cmd->powershell Get-AppxPackage | % { Add-AppxPackage -DisableDevelopmentMode -Register "$($ ...
- CodeIgniter学习笔记一:基本结构、控制器、视图、超级对象、数据库
一.基本结构 CodeIgniter3.0.0解压后有8个文件,分别是: application:项目文件 system:系统(框架)文件,为方便升级,不建议修改 user_guid:用户手册,不需要 ...
- Python 装饰器初探
Python 装饰器初探 在谈及Python的时候,装饰器一直就是道绕不过去的坎.面试的时候,也经常会被问及装饰器的相关知识.总感觉自己的理解很浅显,不够深刻.是时候做出改变,对Python的装饰器做 ...
- CPU指令集不同导致的core分析
最近程序需要支持CGSL系统运行,测试中发现相同操作系统的两台机器,编译机运行正常,测试机coredump.core信息汇总如下,可以看出是由于测试机不支持编译后的指令导致的问题: Program t ...
- jquery实现各种实例
1.正反选实例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- KVC 开发详情
目录 概述 KVC基本技术 KVC访问函数 KVC搜索顺序 KVC集合操作 一.概述 kvc全名是Key-value coding,kvc是一种通过字符串间接的访问oc对象的属性的一种技术. 一个oc ...
- shit vue-cli & path bug & baseUrl bug
vue-cli path bug https://cli.vuejs.org/zh/guide/#cli baseUrl bug baseUrl: "././" , https:/ ...
- hdu 2578 Dating with girls(1) (hash)
Dating with girls(1) Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- [洛谷P4725]【模板】多项式对数函数
题目大意:给出$n-1$次多项式$A(x)$,求一个 $\bmod{x^n}$下的多项式$B(x)$,满足$B(x) \equiv \ln A(x)$.在$\bmod{998244353}$下进行.保 ...
- 【BestCoder #44】
因为这场比赛,我愉快地逃掉了晚自修. T1一开始各种SillyB,忘了40%的最低限制... T2各种想吐槽... 明明OJ警告说%lld是不行的我就换成%I64D(上面写这样的)... 结果各种WA ...