Artwork 18年中南多校第一场A
一、题意
对于一个矩阵,若干道命令,每道命令将会把某一段格子涂黑,请问每次涂黑之后矩阵中未被涂黑的块的数量?
二、思路
保存每道命令,并且忠实的执行他,到最后一步开始搜索联通块的数量,并将其保存。
之后对于每道命令做撤回操作。每次撤回之后重新扫描命令覆盖区域中已经是空白块的区域。并且将它们用并查集的方式统一起来。
最后倒序输出保存的答案。
三、代码实现
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<queue> using namespace std;
#define ll long long
#define veci vector<int>
#define pp pair<ll,ll>
#define vecp vector<pp> const ll MAXN=; class point
{
public :
int x;int y;
point(){}
point(int a,int b):x(a),y(b){}
bool const operator == (point const &p1)
{
return x==p1.x&&y==p1.y;
}
}; class order
{
public :
point from,to;
order(){}
order(int a,int b,int c,int d)
{
from = point(a,b);
to = point(c,d);
}
};
ll n,m,k,num;
vector<order>ord;
veci ans;
point sett[MAXN][MAXN];
int mapp[MAXN][MAXN];
int addx[]={,,,-};
int addy[]={,-,,}; void draw(order o1)
{
for(int i=o1.from.x;i<=o1.to.x;++i)
{
for(int j=o1.from.y;j<=o1.to.y;++j)
{
if(mapp[i][j]==-)mapp[i][j]=;
mapp[i][j]++;
}
}
}
void erase(order o1)
{
for(int i=o1.from.x;i<=o1.to.x;++i)
{
for(int j=o1.from.y;j<=o1.to.y;++j)
{
mapp[i][j]--;
}
} } const point ZERO(,); void dfs(int x,int y,point tar)
{
if(x<||x>n||y<||y>m||mapp[x][y]!=-||sett[x][y]==tar)return ;
sett[x][y]=tar;
mapp[x][y]=;
for(int i=;i<;++i)
{
dfs(x+addx[i],y+addy[i],tar);
}
} point find_set(int x,int y)
{
if(sett[x][y].x==x&&sett[x][y].y==y)return sett[x][y];
else return sett[x][y]=find_set(sett[x][y].x,sett[x][y].y);
} void show(point p1)
{
int x=p1.x;
int y=p1.y;
cout<<"x: "<<x<<" y: "<<y<<endl;
} void deal(order o1)
{
for(int i=o1.from.x;i<=o1.to.x;++i)
for(int j=o1.from.y;j<=o1.to.y;++j)
{
if(mapp[i][j]==)
{
int isDealed=;
for(int k=;k<;++k)
{
int x=i+addx[k];
int y=j+addy[k];
if(x<||y<||x>n||y>m)continue;
if(mapp[x][y]==)
{
if(sett[x][y]==ZERO)continue;
if(!isDealed)
{
sett[i][j]=sett[x][y]=find_set(x,y); }else
{ sett[x][y]=find_set(x,y);
sett[i][j]=find_set(i,j);
if(sett[i][j]==sett[x][y])continue;
int xx=sett[x][y].x;
int yy=sett[x][y].y;
sett[xx][yy]=sett[i][j];
num--;
}
isDealed++;
}
}if(!isDealed)
{
sett[i][j]=point(i,j);
num++;
} }
} } void init()
{
num=;
ord.clear();
ans.clear();
memset(mapp,-,sizeof(mapp));
memset(sett,,sizeof(sett));
for(int i=;i<k;++i)
{
int a,b,c,d;
cin>>a>>b>>c>>d;
order o1(a,b,c,d);
draw(o1);
ord.push_back(o1);
}
for(int i=;i<=n;++i)
for(int j=;j<=m;++j)
{
if(mapp[i][j]==-)
{
point tar(i,j);
dfs(i,j,tar);
num++;
}
}
ans.push_back(num); int len=ord.size();
for(int i=len-;i;--i)
{
order now=ord[i];
erase(now);
deal(now);
ans.push_back(num);
}
len = ans.size();
for(int i=len-;i>=;--i)
cout<<ans[i]<<endl; } int main()
{
// cin.sync_with_stdio(false); while(cin>>n>>m>>k)init(); return ;
}
Artwork 18年中南多校第一场A的更多相关文章
- Card Hand Sorting 18中南多校第一场C题
一.题意 随机给你一堆牌(标准扑克牌),之后让你按照: 第一优先规则:所有相同花色的在一起 第二优先规则:所有相同花色的必须按照升序或者降序排列 问,你最少要拿出多少张牌插入到其他的地方以维持这个状况 ...
- Highest Tower 18中南多校第一场H题
一.题意 给出N个方块,要求给出一个方案,使得1. 所有方块都被使用到(题目数据保证这点) 2.所有方块垒成一个塔,且上面的方块宽度小于下面的方块 3.每个方块只能用一次,可以横着或者竖着. n范围5 ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- HDU6581 Vacation (HDU2019多校第一场1004)
HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...
- 2019年牛客多校第一场B题Integration 数学
2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...
- 2019HDU多校第一场1001 BLANK (DP)(HDU6578)
2019HDU多校第一场1001 BLANK (DP) 题意:构造一个长度为n(n<=10)的序列,其中的值域为{0,1,2,3}存在m个限制条件,表示为 l r x意义为[L,R]区间里最多能 ...
- 2019年湖南多校第一场||2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018)
第一场多校就打的这么惨,只能说自己太菜了,还需继续努力啊- 题目链接: GYM链接:https://codeforces.com/gym/101933 CSU链接:http://acm.csu.edu ...
- 【2019多校第一场补题 / HDU6578】2019多校第一场A题1001Blank——dp
HDU6578链接 题意 有一串字符串,仅由 {0,1,2,3}\{0, 1, 2, 3\}{0,1,2,3} 组成,长度为 nnn,同时满足 mmm 个条件.每个条件由三个整数组成:l.r.xl.r ...
随机推荐
- Spring整合Struts2 注解版
1.jar包 <!--spring配置--> <dependency> <groupId>org.springframework</groupId> & ...
- 关于myeclipse导入项目时出现的中文注释乱码问题
要设置myeclipse的编码,需要了解各个设置项的作用 第一类编码设置项,虽然有三处设置,但是是可以归为一类的 第一处为myeclipse的工作区(workspace),其范围最 ...
- juypter-notebook安装配置
juypter-notebook安装配置 Table of Contents 1. jupyter notebook概述 2. jupyter notebook安装 3. 在jupyter noteb ...
- ABAP WRITE
1.空行 WRITE /. 2.AS CHECKBOX VALUE 'X', check2 VALUE ' '. START-OF-SELECTION. WRITE: / check1 AS CHEC ...
- cms-最近更新
在这一讲中有几个很重要的地方需要注意: 1.在查询帖子的时候需要把帖子类型id带到帖子类型表中把类型查询出来 2.在字帖子查询语句中用limt限制查询那个阶段的帖子 3.在界面显示的时候需要用到字符串 ...
- TFS看板的设计
列 产品开发的整个流程如下图,将流程配置到看板的列: 需求池-->就绪-->开发-->测试-->待验收 -->待发布 -->已关闭 一般将Bug和需求放在一块看版上 ...
- 解决MVC运行controller的时候只有有参构造函数但是程序一定要走无参构造函数的方法
方法如下 https://www.codeproject.com/Articles/560798/ASP-NET-MVC-Controller-Dependency-Injection-for-Be
- python_77_json与pickle序列化3
#此方法:dump多次,而不可以load多次,只能load一次,否则会出错 只有序列化,无反序列化 import json info={ 'name':'Xue Jingjie', 'age':22, ...
- 跟我一起从零开始学WCF系列课程
http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/Series/WCF_Begin.aspx 服务和协定 服务协定使 ...
- C#的接口基础教程之六 接口转换
C#中不仅支持.Net 平台,而且支持COM平台.为了支持 COM和.Net,C# 包含一种称为属性的独特语言特性.一个属性实际上就是一个 C# 类,它通过修饰源代码来提供元信息.属性使 C# 能够支 ...