玻璃切割

思路:

  并查集;

  离线操作;

  先把每次切割都存下来;

  然后从后面不断合并切割;

  然后每次更新最大长和宽;

  记录答案;

  要开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的更多相关文章

  1. AC日记——最高奖励 51nod 1163

    最高的奖励 思路: 排序: 时间为第一关键字,按总小到大排: 价值为第二关键字,按从大到小排: 然后,不难看出,如果两个时间不同: 那么,两个时间之间最少能做一件事: 因为他们的时间下限最少相差1: ...

  2. AC日记——幸运号码 51nod 1043

    幸运号码 思路: 传说中的数位dp: 不难发现,n(n<1000) ,那么,n个数的最大和为9*1000=9000: 对于9000*1000的时间范围,我们可以用dp来解决: dp[i][j], ...

  3. AC日记——石子归并 51nod 1021

    石子归并 思路: 经典动态规划——归并类问题: 我们把状态划为n个,即1-n的n个长度为n个状态: 那么,每个长度为i的状态都可以由i-1个长度为i-1的状态推出: 所以,dp转移方程: dp[i][ ...

  4. AC日记——背包问题 V2 51nod 1086

    有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi ...

  5. 51nod 1562 玻璃切割

      1562 玻璃切割 http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1562 题目来源: CodeForces 基准时间 ...

  6. 51nod 1562 玻璃切割 (STL map+一点点的思考)

    1562 玻璃切割 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 现在有一块玻璃,是长方形的(w 毫米× h 毫米),现在要 ...

  7. AC日记——codevs1688求逆序对

    AC日记--codevs1688求逆序对 锵炬 掭约芴巷 枷锤霍蚣 蟠道初盛 到被他尽情地踩在脚下蹂躏心中就无比的兴奋他是怎么都 ㄥ|囿楣 定要将他剁成肉泥.挫骨扬灰跟随着戴爷这么多年刁梅生 圃鳋 ...

  8. 51nod 1562 玻璃切割 (set)

    #include<stdio.h> #include<iostream> #include<set> using namespace std; typedef lo ...

  9. AC日记——最小正子段和 51nod 1065

    最小正子段和 思路: 找最小的大于0的sum[j]-sum[i](j>i): 高级数据结构(splay)水过: 来,上代码: #include <cstdio> #include & ...

随机推荐

  1. echart搭配时间轴进行展示 (本例展示的是多时间 多地区 多指标条件 )

    1:照常先来几张图 看效果  2:首先 看官方文档 我把echart官方的例子给扒下来并整理了得出如下效果 上 案例图和代码 效果图 : 代码: <style type="text/c ...

  2. JFinal 添加Druid插件

    第一步:添加依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</a ...

  3. Python 实现随机打乱字符串

    from random import shuffle def shuffle_str(s): # 将字符串转换成列表 str_list = list(s) # 调用random模块的shuffle函数 ...

  4. Canvas 剪切图片

    /** * 剪切图像 */ function initDemo8(){ var canvas = document.getElementById("demo8"); if (!ca ...

  5. [译]11-spring bean定义的继承

    spring中bean的定义包含很多信息,如,构造器参数.property指定的依赖项.初始化方法.工厂类和工厂方法等. 如果spring容器的中每个bean都重复声明这些属性,是非常烦人也是十分低效 ...

  6. FlexGrid布局

    FlexGrid布局: Grid布局时网格大小是固定的,如果想网格大小不同的界面可以使用FlexGrid布局.FlexGrid是更加灵活的Grid布局.FlexGrid布局类是wx.FlexGridS ...

  7. Ubuntu16.04安装openCV的问题集合

    Q1 下列软件包有未满足的依赖关系:   libtiff4-dev : 依赖: libjpeg-dev  E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系. 上网查了 ...

  8. shell sort 排序大讨论

    转自http://roclinux.cn 本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. === [正文开始]有时候学 ...

  9. 从 C10K 到 C500K

    国外的 Urban Airship 公司的工程师在其官方网志上发文章介绍他们在产品环境中做到 50 万并发客户端,Java + Pure NIO 的实现,最近又有文章介绍针对 Linux Kernel ...

  10. html & email template

    html & email template inline style build tools https://templates.mailchimp.com/getting-started/h ...