总时间限制: 
40000ms

单个测试点时间限制: 
4000ms

内存限制: 
128000kB
描述

从前有一座岛屿,这座岛屿是一个长方形,被划为N*M的方格区域,每个区域都有一个确定的高度。不幸的是海平面开始上涨,在第i年,海平面的高度为t[i]。如果一个区域的高度小于等于海平面高度,则视为被淹没。那些没有被淹没的连通的区域够成一个连通块。现在问第i年,这样的连通块有多少个。

例如:第一年海平面高度为1,有2个连通块。

第二年海平面高度为2,有3个连通块。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAikAAADrCAIAAAAjTpHfAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAgAElEQVR4nO3deVxU9f4/8NeAKIooCrgnDS7krpQ1itrV5GoWVnotJTXJXVETE0XDLpmaiYKk93fdrqhxc8lvXXHDLURxvUCCAqKCiikgCrLDwJzfH7gMrldjPp+ReT3/8eFnzsz7fc583rxnzpxFpSgKiIiIBDKTnQAREZkc9h4iIhKNvYeIiERj7yEiItHYe4iISDT2HiIiEo29h4iIRGPvISIi0dh7iIhINPYeIiISrVolvY5SeOdWEapbVDNX3RvRlWqLVTXt6lg+tGB2ZqFSvVr5kkpZSYmZVf3a1SspDSLTxAKkl0xlfe8pS/rRvr5NXeva91nXsalvvzX54QWLz/2rge39Ja3r1h+y81ol5VBptGm/BayPKZCdBtH/rEoUoO5O0r5/ePV3Uqkadhvpt+FwSp5OdkpkOErlKogK7Fj+wv+MLXvSQiUxPwANpv6cnK+r5PB/iq4k72Zy1K4fxjoDmL7/pux8iJ7bS1uAuswIv64N3P13RV24cjnxxLZ57wJAA88dqVrZqZFBVPbvPTWdx639HgAw4R9haY9fRnc9OXLotpPLBqtrqR6/hATx61RmzXpPWX2yrFl7B9nJEL2gl7QAdclbPFY4hlwNmTHAuWVzB6e3/ua3M23PVGSsGPjKwshc2emRIRign+Uc9St/7VmHbj/m4bQ9k/psSDTeDzM3do0Fv/fQy+vlK8CCU99jwaFbxRVHdUmbXADAeeN5OWm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M8N+XHrPPxtt5/x0/vDl3N6a/hNJmAC0Um6vKhAN1/741nL9f7w3TkavDfNBKKbcgKm3nu0V3b4LDRf8O+JznX0jqtS0i7esBLzzdPEE5C++iSXNnnzeG+zlftmaWz0J8C1xKvWVk9+VtWIbuIJGFnvEXsNL11m+EKv66NWurc0L7qvMD/n5okDcxraCDi30cQTkL76VIHwK+jpMsK8R6Z6bhnf1uLB+1+Ql50eHjq2aT2DX0tTanQmYCy710syrkQCiL2WWQo7MUnl/b7qU4/gJAS/vvjRB6dsGcEEqnJ00iOh+gDknlzi2j8wFoH23o8+OC9iYlWOzgSkf++5dehLlUqlUqlqdJoUD+CQRxuL8gHfiGzDhr6w86Pvn3yp1iaG/9hh4glIX32SWH0A4rdqZsc+8dHmtnWrcHQmAOnfe2z7+CuKv5TQrYampAyVEpkJyI9OkFp9KL+Dw2hZwSVHZwKQ/r2HiIhMEHsPERGJxt5DRESisfcQEZFo7D1ERCQaew8REYnG3kNERKKx9xARkWjsPUREJBp7DxERiVY519RRqVRHjhyZPHlypbzaC8jJyQkNDY2Li5MSvaSkBMCHH35obm4uJYGUlBStVtuvXz8p0QEUFxfv3LkzNvbJ14cypIyMDJ1OJyW0kcjKypo+fXqLFi2kRL927doff/whsfxjYmJu3LgRHx8vJbpOp6tWrZqXl5eFhYWUBBITE1NTUyVu/6NHj3p7P+aCpE+nUpRKuHJ6bm7uDz/8ILH+r169mpycLCs6gMzMTDs7O1nRi4uLi4uL69SpIyuBrKwsa2vratWkXR6wU6dOS5culRVdum3btp0/f152FmSiLCwsJkyYULfu811+tHJ6DxER0f+Ov/cQEZFo7D1ERCQaew8REYnG3kNERKKx9xARkWjsPUREJBp7DxERicbeQ0REorH3EBGRaOw9REQkGnsPERGJxt5DRESisfcQEZFo7D1ERCQaew8REYnG3kNERKKx9xARkWjsPUREJBp7DxERicbeQ0REorH3EBGRaP8f8nScUNW2XfIAAAAASUVORK5CYII=" alt="" width="553" height="235" />

输入
第一行包含两个数N,M。
接下来是一个N*M的矩阵,第i行第j列表示这个格子的高度h[i][j]
接下来是一个数T,表示有T天,
最后一行有T个数,第i个数表示第i天的水位高度。(保证是递增的)
输出
输出包含一行T个数,第i个数表示第i天的连通块个数。
样例输入
4 5
1 2 3 3 1
1 3 2 2 1
2 1 3 4 3
1 2 2 2 2
5
1 2 3 4 5
样例输出
2 3 1 0 0
提示
对于50%的数据: 1 <= n*m <= 1000, 1<= T <=3000
对于100%的数据:1<= n <= 3000 , 1<= m <= 3000 , 1<=T<=100000 
1<= h[i][j] <=10^9
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int t[],ans[],f[],n,m,tot,si;
struct node{
int x,y,high;
}a[];
bool vis[];
int cmp(node i,node j){return i.high>j.high;}
int dx[]={,,,-};
int dy[]={-,,,};
int find(int x){
if(x==f[x]) return x;
else return f[x]=find(f[x]);
}
void solve(){
int sum=,pos=;
sort(a+,a+tot+,cmp);
for(int p=si;p>=;p--){
for(int i=pos;i<=tot;i++){
int h=a[i].high,x=a[i].x,y=a[i].y;
if(h<=t[p]){ pos=i;break; }
if(h>t[p]&&!vis[(x-)*m+y]) {
sum++;vis[(x-)*m+y]=true;
for(int j=;j<;j++){
int nx=x+dx[j],ny=y+dy[j];
int k1=find((nx-)*m+ny),
k2=find((x-)*m+y);
if(nx>&&nx<=n&&ny>&&ny<=m
&&vis[k1]&&k1!=k2){
sum--;f[k1]=k2;
}
}
}
}
ans[p]=sum;
}
for(int i=;i<=si;i++) printf("%d ",ans[i]);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%d",&a[++tot].high);
a[tot].x=i;a[tot].y=j;
}
for(int i=;i<=tot;i++) f[i]=i;
scanf("%d",&si);
for(int i=;i<=si;i++) scanf("%d",&t[i]);
solve();
return ;
}

神一样的倒序并查集。。。。

OpenJudge 东方14ACM小组 / 20170123 02 岛屿的更多相关文章

  1. OpenJudge 东方14ACM小组 / 20170123 06:Challenge 3

    总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  262144kB 描述 给一个长为N的数列,有M次操作,每次操作是以下两种之一: (1)修改数列中的一个数 (2)求 ...

  2. 东方14ACM小组 Challenge 11

    总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  262144kB 描述 给一个长为N的数列,有M次操作,每次操作是以下两种之一: (1)修改数列中的一个数 (2)求 ...

  3. 东方14ACM小组 15:Challenge 11

    Challenge 11 查看 提交 统计 提问 总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  262144kB 描述 给一个长为N的数列,有M次操作,每次操作是 ...

  4. 常用OJ名字+地址(自用)

    常用OJ名字+地址 不定期更新,自己用,有补充的也可以给我说说哈. 中文 openjudge 地址:openjudge.cn 说明:北大提供的一个平台,学校可申请小组: 比较好的小组: 计算概论:ic ...

  5. AC日记——找第一个只出现一次的字符 openjudge 1.7 02

    02:找第一个只出现一次的字符 总时间限制:  1000ms 内存限制:  65536kB 描述 给定一个只包含小写字母的字符串,请你找到第一个仅出现一次的字符.如果没有,输出no. 输入 一个字符串 ...

  6. noi题库(noi.openjudge.cn) 1.11编程基础之二分查找T01、02、04

    T01 查找最接近的元素 描述 在一个非降序列中,查找与给定值最接近的元素. 输入 第一行包含一个整数n,为非降序列长度.1 <= n <= 100000.第二行包含n个整数,为非降序列各 ...

  7. 【Openjudge】岛屿(并查集)

    题目链接 此题是并查集.考虑到水位不断上涨,所以将时间倒转.先统计最后一天的联通块个数,每一天浮出水面的块进行计算.复杂度O(玄学). 代码如下 #include<cstdio> #inc ...

  8. OpenJudge/Poj 1251 丛林中的路/Jungle Roads

    1.链接地址: http://bailian.openjudge.cn/practice/1251/ http://poj.org/problem?id=1251 2.题目: 总时间限制: 1000m ...

  9. 一个用python实现的东方时尚(驾校)抢课程序

    2014-12-23 东方时尚约车还要网上选课,资源太紧张了,于是我决定自己写一个抢票程序来帮我刷票. 第一步,抓包.浏览器登陆选课系统,用抓包工具观察网络行为,这里我用的fildder.这里抓包主要 ...

随机推荐

  1. javaweb基础(18)_jsp属性范围

    所谓的属性范围就是一个属性设置之后,可以经过多少个其他页面后仍然可以访问的保存范围. 一.JSP属性范围 JSP中提供了四种属性范围,四种属性范围分别指以下四种: 当前页:一个属性只能在一个页面中取得 ...

  2. Codevs1081 线段树练习 2

    题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ...

  3. C++系统学习之九:顺序容器

    元素在顺序容器中的顺序与其加入容器时的位置相对应.关联容器中元素的位置由元素相关联的关键字值决定.所有容器类都共享公共的接口,不同容器按不同方式对其进行扩展. 一个容器就是一些特定类型对象的集合.顺序 ...

  4. poj1654 Area

    题目描述: vjudge POJ 题解: 本以为是水题结果是神题 计算几何求多边形面积. 考虑到结果一定是整数或者整数/2,我们应该用long long 来存…… 用double会死…… 还有日常只能 ...

  5. Maven配置项目依赖使用本地仓库的方法汇总

    Maven配置项目使用本地仓库有以下方式实现: 1.类似本地仓库,但是属于本地依赖,比如某个JAR包是引用第三方的,直接放在了项目的lib文件夹,那么此时可以如下配置项目的POM: <depen ...

  6. solr配置中文分词器

    配置IK分词器 在/opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF/lib目录中加入IK分词器的jar包 在/opt/solr-7.7.1/serve ...

  7. LeetCode(205)Isomorphic Strings

    题目 Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ch ...

  8. stm32之Cortex系统定时器(SysTick)

    转载自:http://www.21ic.com/app/mcu/201811/781135.htm   SysTick时钟,俗称“嘀嗒定时器”,它能按设定的时间产生一次中断.控制工程代码中随处可见形如 ...

  9. poj 2376 选择工作区间问题 贪心算法

    题意:给一些工作区间,如何选取最小的工作数量,覆盖[1,T]的工作时长 一开始的思路,当然也是错误的思路: 我想着,最小工作数量是吧?那肯定就是选择结束时间最晚的,给结束时间来一个排序.哎这个思路错误 ...

  10. Linux学习-额外(单一)核心模块编译

    编译前注意事项 由于我们的核心原本就有提供很多的核心工具给硬件开发商来使用, 而硬件开发商也需要针对核心 所提供的功能来设计他们的驱动程序模块,因此, 我们如果想要自行使用硬件开发商所提供的模块 来进 ...