玻璃切割

思路:

  并查集;

  离线操作;

  先把每次切割都存下来;

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

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

  记录答案;

  要开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. springboot 入门2 开发环境与生产环境采用不同配置问题

    目开发中我们通常有两套配置信息  分别配置了我们的数据源信息等? 那么我们要如何不通过修改配置文件大量配置来实现简单的修改与配置来实现相关配置加载功能 首先springboot 有一个核心的配置文件a ...

  2. 斐波那契数列(递归)&求100以内的素数

    Java 5 添加了 java.util.Scanner 类,这是一个用于扫描输入文本的新的实用程序.它是以 前的 StringTokenizer 和 Matcher 类之间的某种结合.由于任何数据都 ...

  3. gettid 和pthread_self的区别

    转: Linux中,每个进程有一个pid,类型pid_t,由getpid()取得.Linux下的POSIX线程也有一个id,类型 pthread_t,由pthread_self()取得,该id由线程库 ...

  4. JavaSE总结--多线程

    进程: 进程之间内存隔离,内存不共享. 线程: 可以共享内存. 每个线程都是一个栈. 多线程的好处: 1)防止程序阻塞. wait与notify的区别: 针对等待队列而言. wait:进入等待队列.必 ...

  5. 1099 Build A Binary Search Tree (30 分)(查找二叉树)

    还是中序遍历建树 #include<bits/stdc++.h> using namespace std; ; struct node { int data; int L,R; }s[N] ...

  6. [译]如何去除pandas dataframe里面的Unnamed的列?

    原文来源: https://stackoverflow.com/questions/43983622/remove-unnamed-columns-in-pandas-dataframe 问:我有一个 ...

  7. Android 开发中Service完全解析

    定义:服务,是Android四大组件之一,属于计算型组件 作用:提供 需在后台长期运行的服务 生命周期:          在Service的生命周期里,常用的有: (1) 4个手动调用的方法 手动调 ...

  8. 点对点协议(Point-to-Point Protocol)

    简介 点对点协议简称PPP协议,工作在数据链路层.设计目的主要是用来通过拨号或专线方式建立点对点连接发送数据,使其成为各种主机. 网桥和路由器之间简单连接的一种共通的解决方案. PPP协议的组成 建立 ...

  9. POJ 3180 The cow Prom Tarjan基础题

    题目用google翻译实在看不懂 其实题目意思如下 给一个有向图,求点个数大于1的强联通分量个数 #include<cstdio> #include<algorithm> #i ...

  10. 《c程序设计语言》读书笔记-4.1-判断字符串在另一个字符串中的位置

    #include <io.h> #include <stdio.h> #include <string.h> #include <stdlib.h> # ...