链接: https://www.nowcoder.com/acm/contest/106/L
来源:牛客网

It’s universally acknowledged that there’re innumerable trees in the campus of HUST.

And you know that, trees have the special ability to refresh the air. If an area, which is surrounded by trees, is separated from the outer atmosphere, you can call it “the supercalifragilisticexpialidocious area”. Students can enjoy the healthiest air there. Then, you happened to know that HUST will plant N trees in a bare plain, so you want to calculate the total size of “the supercalifragilisticexpialidocious area” after each operation.
We describe the position of trees with a coordinate.(Xi,Yi).
For example, after 9 trees were planted, the green area is a supercalifragilisticexpialidocious area, its size is 3.

#include <bits/stdc++.h>using namespace std;
#define mp make_pair
const int maxn = 2000;
int e[maxn+32][maxn+32], cnt;
const int dirx[] = {0,0,1,-1};
const int diry[] = {1,-1,0,0};
bool inside(int i,int j)
{return i>=0&&i<=maxn&&j>=0&&j<=maxn;
}
pair<int,int> p[100007];
int res[100007];
void bfs(int x, int y)
{queue<pair<int,int> > que;que.push(mp(x, y));e[x][y] = 2;while(!que.empty()) {cnt --;auto it = que.front();  que.pop();int x, y;tie(x, y) = it;for(int i = 0;i < 4;i ++) {int dx = x + dirx[i];int dy = y + diry[i];if(inside(dx, dy) && e[dx][dy] == 0) {e[dx][dy] = 2;que.push(mp(dx, dy));}}}
}
int main()
{int n;scanf("%d", &n);for(int i = 1;i <= n;i ++) {int x, y;scanf("%d %d", &x, &y);x += 1000, y += 1000;e[x][y] = 1; // tree is 1p[i] = mp(x, y);}cnt = 2001 * 2001 - n;bfs(0, 0);auto check = [&](int x, int y) ->bool{for(int i = 0;i < 4;i ++) {int dx = x + dirx[i];int dy = y + diry[i];if(inside(dx, dy) && e[dx][dy] == 2) return 1;}return 0;};for(int i = n;i >= 1;i --) {res[i] = cnt ++;int x, y;tie(x,y) = p[i];e[x][y] = 0;if( check(x ,y) ) bfs(x, y);}for(int i = 1;i <= n;i ++) printf("%d\n",res[i]);return 0;
}

After planting a new tree in (3,2), its size is 2.

输入描述:

The first line is an integer N as described above.
Then following N lines, each line contains two integer Xi and Yi, indicating a new tree is planted at (Xi,Yi).

输出描述:

Output N lines, each line a integer indicating the total size of supercalifragilisticexpialidocious areas after each operation.

这里解释一下为什么从(0,0)开始,我们知道坐标范围是,坐标在输入时处理了一下,都加了1000,

那么处理后的坐标范围就是(1<Xi,Yi<2000),我们要想在图中都把没被围这空地0走一遍,不能在坐标范围(1<Xi,Yi<2000)中随便找一个坐标就走,不实际,为什么?因为你选的坐标可能走着走着就不能继续走了,但还有空地0(没被围的)没去走并赋值为空地2。这时那我们该怎么解决这个问题呢?很简单,将坐标范围(1<Xi,Yi<2000)的圈外多加单位为1的圈,围住坐标范围(1<Xi,Yi<2000),这时我们可以在多加的一圈内随便找一个点去搜(哪个坐标顺眼就选哪个),这样就能保证能从范围(1<Xi,Yi<2000)圈外的任意个位置进去搜,嗯呢,搞定。啊,我这么热心肠,还是画个图吧!

第十四届华中科技大学程序设计竞赛-L—Fresh Air,bfs拓展,倒着bfs相关推荐

  1. 第十四届华中科技大学程序设计竞赛 B Beautiful Trees Cutting【组合数学/费马小定理求逆元/快速幂】...

    链接:https://www.nowcoder.com/acm/contest/106/B 来源:牛客网题目描述 It's universally acknowledged that there're ...

  2. 第十四届华中科技大学程序设计竞赛--J Various Tree

    链接:https://www.nowcoder.com/acm/contest/106/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...

  3. A ZJH and Monkeys 第十四届华中科技大学程序设计竞赛

    链接: https://www.nowcoder.com/acm/contest/106/A 来源:牛客网 It's universally acknowledged that there're in ...

  4. 第十四届中北大学ACM程序设计竞赛 J.ZBT的游戏

    问题描述 第14届中北大学程序设计竞赛来了,集训队新买了一大堆气球,气球一共有K种颜色(1<=K<=256),气球的颜色从1-K编号. ZBT童心未泯,他发明了一种摆放气球的游戏,规则如下 ...

  5. 河南省第十四届ICPC大学生程序设计竞赛

    题目链接 https://ac.nowcoder.com/acm/contest/58860 分组背包问题 有 N N N 组物品和一个容量是 V V V 的背包. 每组物品有若干个,同一组内的物品最 ...

  6. 2018年湖南省第十四届大学生计算机程序设计竞赛 CSU 2164: 2018

    题目传送门 不会自己推,比赛现场找规律. 代码: #include<bits/stdc++.h> using namespace std;typedef long long LL; con ...

  7. 2022年第十四届“华中杯”大学生数学建模挑战赛

    2022年第十三届"华中杯"大学生数学建模挑战赛   为了推广我国高校数学建模实践教学,培养学生的创新意识及运用数学方法和计算机技术解决实际问题的能力,第十四届"华中杯& ...

  8. 第十五届北京师范大学程序设计竞赛决赛(网络同步赛) B lca水 D 思维,找规律...

    第十五届北京师范大学程序设计竞赛决赛(网络同步赛) B. Borrow Classroom 题意:一棵树,点 1为根,一个人从点 b到 点 c再到点 1,第二个人从点 a出发,问第二个人能否截住第一个 ...

  9. 2022年第十四届全国大学生数学竞赛

    11.12非延迟地区开赛啦,小编为大家整理了2022年第十四届全国大学生数学竞赛真题加标答 希望帮到大 家   大学竞赛君自做答案90+,延迟地区的小伙伴也可以辅导

最新文章

  1. JAVA IO操作中的IN和OUT问题
  2. Oracle数据库知识要点
  3. JAVA实现inotify一样的功能_哪些操作系统支持在Java中查看本机(类似inotify)文件
  4. 弱引用什么时候被回收_ThreadLocal的内存泄露?什么原因?如何避免?
  5. 图片上传unexpected end of stream
  6. Spring 思维导图,让 Spring 不再难懂(cache篇)
  7. Java开发人员应该知道的5大Spring Boot功能
  8. Windows Service Application Overview
  9. 高级版本VS打开低版本VS工程,无法调试的问题
  10. Axure+SVN——实现多人团队开发
  11. 简短介绍_简短的自我介绍
  12. 【Java】Java字符串拼接的五种方法,哪种性能最好?
  13. Ant Design Vue - 修改<Table>表格组件默认的暂无数据图标(自定义表格空数据状态图片)
  14. 重磅 | 完备的人工智能AI 学习——基础知识学习路线,所有资料免关注免套路直接网盘下载
  15. 设置页面包含子页面iframe用法
  16. 珍惜现在才能活的快乐
  17. Java实现等额本金
  18. 二维码与条形码的生成和识别使用
  19. 【100%通过率】华为OD机试真题 Java 实现【预订酒店】【2022.11 Q4 新题】
  20. 书签书签书签书签书签书签

热门文章

  1. selenium启动ie配置,实现inprivate浏览,禁止ie缓存
  2. 关于Bilibili的1024题库获取
  3. python 爬虫抓取心得分享
  4. 思科高级配置(三层交换配置路由)
  5. 狂神说笔记——SpringBoot操作数据库22-5
  6. 刚刚!2022年QS世界大学排名发布:清华北大跻身前20!国内大学排名创纪录......
  7. 京东高风险用户判定参考
  8. Kotlin Navigation开发
  9. CreoParametric 4.0 突然退出(崩溃)问题
  10. win10如何用管理员身份打开hosts文件