CF327D (dfs)

【信息科学与工程学】【数据科学】数据科学领域 第六篇 算法设计 01 算法设计 阅读详情

After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n × m cells). The goal of the game is to build your own city. Some cells in the grid are big holes, where Iahub can't build any building. The rest of cells are empty. In some empty cell Iahub can build exactly one tower of two following types:

  1. Blue towers. Each has population limit equal to 100.
  2. Red towers. Each has population limit equal to 200. However, it can be built in some cell only if in that moment at least one of the neighbouring cells has a Blue Tower. Two cells are neighbours is they share a side.

Iahub is also allowed to destroy a building from any cell. He can do this operation as much as he wants. After destroying a building, the other buildings are not influenced, and the destroyed cell becomes empty (so Iahub can build a tower in this cell if needed, see the second example for such a case).

Iahub can convince as many population as he wants to come into his city. So he needs to configure his city to allow maximum population possible. Therefore he should find a sequence of operations that builds the city in an optimal way, so that total population limit is as large as possible.

He says he's the best at this game, but he doesn't have the optimal solution. Write a program that calculates the optimal one, to show him that he's not as good as he thinks.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 500). Each of the next n lines contains m characters, describing the grid. The j-th character in the i-th line is '.' if you're allowed to build at the cell with coordinates (i, j) a tower (empty cell) or '#' if there is a big hole there.

Output

Print an integer k in the first line (0 ≤ k ≤ 106) — the number of operations Iahub should perform to obtain optimal result.

Each of the following k lines must contain a single operation in the following format:

  1. «B x y» (1 ≤ x ≤ n, 1 ≤ y ≤ m) — building a blue tower at the cell (x, y);
  2. «R x y» (1 ≤ x ≤ n, 1 ≤ y ≤ m) — building a red tower at the cell (x, y);
  3. «D x y» (1 ≤ x ≤ n, 1 ≤ y ≤ m) — destroying a tower at the cell (x, y).

If there are multiple solutions you can output any of them. Note, that you shouldn't minimize the number of operations.

Sample test(s)
input
2 3
..#
.#.
output
4
B 1 1
R 1 2
R 2 1
B 2 3
input
1 3
...
output
5
B 1 1
B 1 2
R 1 3
D 1 2
R 1 2

思路: 对于每一个.联通块,只有一个图b,别的先涂b再图周围的,然后再图d,再图 R


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 505

struct stud{
  stud(char a,int x,int y):x(x),y(y),ch(a){}
  stud(){}
  int x,y;
  char ch;

 void print(){printf("%c %d %d\n",ch,x,y);}

}f[N*N*3];

int k;

int step[4][2]={1,0,-1,0,0,1,0,-1};

int n,m;
char a[N][N];
int vis[N][N];

inline bool judge(int x,int y)
{
	return x>=1&&x<=n&&y>=1&&y<=m;
}


void dfs(int x,int y,int dep)
{
	a[x][y]='#';
	 f[k++]=stud('B',x,y);
     int i,j;
     fre(i,0,4)
     {
     	int xx=x+step[i][0];
     	int yy=y+step[i][1];

     	if(judge(xx,yy)&&a[xx][yy]=='.')
		{
			dfs(xx,yy,1);

		}
     }

     if(dep)
	 {
	 	f[k++]=stud('D',x,y);
	 	f[k++]=stud('R',x,y);
	 }
}

int main()
{
	int i,j;
	while(~sff(n,m))
	{
		k=0;
		for(i=1;i<=n;i++)
		   scanf("%s",a[i]+1);

		fre(i,1,n+1)
			fre(j,1,m+1)
			  if(a[i][j]=='.')
		{
			 dfs(i,j,0);
		}

		pf("%d\n",k);
		for(i=0;i<k;i++)
			f[i].print();

	}
	return 0;
}






【管理科学】第三十五篇 企业经营中的管理科学01 权力、风险、运营、物流、人力资源、库存、合同、品牌、业绩、项目 编号类型领域子领域/内容问题问题的数学分析(电磁/信息论/数学物理/数学化学/界面科学/表面科学 + 几何/拓扑/代数/集合论/图论/数论/函数评估/数值估计/概率/统计/向量/张量/矩阵/矢量 + 其他)算法逐步推理思考的数学表达式及实现步骤及时序流程 参数列表及参数的数值范围及数值分析及常量/常数1管理科学问题运营管理生产计划如何分配有限资源生产多种产品以最大化利润?线性代数、凸优化、单纯形法;向量与矩阵目标函数 max c^T x,约束 Ax ≤ b, x ≥ 0。步骤:①标准化引入松弛变量;②构建初 阅读详情

相关推荐

【信息科学与工程学】【审计学】第一篇 招投标领域审计算法01

在每个关键流程节点(如文件上传、开标唱标、评标结束), 计算该环节所有电子文件的数字指纹(如SHA-256哈希值), 并将指纹和元数据(时间、操作人)上链存证。:从发票、合同中提取材料品名、规格、采购价、时间、地点。:对每个供应商, 提取其在历史投标中的行为序列特征, 如:中标率、与特定伙伴同时投标率、自身高报价次数、在伙伴中标项目中的“弃标”或“无效标”次数。:监控开标、评标现场音视频, 识别异常情绪(激烈争吵)、敏感关键词(“打点”、“关照”)、异常物品传递、私下交流等违规行为。

weixin_49199313的博客 813

codeforces 327D. Block Tower(高级DFS)

After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n × m cells). The goal of the game is to build your own city. Some

风的记忆 432

【信息科学与工程学】【通信工程】第四篇 通信网络的数学架构10 通信网络核心数学方程式01

卸载:Toffload​=L/R+C/fserver​+Tback​, Eoffload​=Ptx​⋅(L/R)。下层:在切片 s内,为用户 u分配资源,最大化对数效用函数 ∑u​log(ru​), 其中 ru​=∑n∈NRBs​​au,n​⋅SEu,n​, au,n​∈{0,1}表示分配。:在时隙 t, 能量到达 Et​, 电池能量状态 Bt​更新:Bt+1​=min(Bt​−pt​+Et​,Bmax​)。:基站发送:x=α1​P​s1​+α2​P​s2​, α1​+α2​=1, α1​>α2​。

weixin_49199313的博客 371

CF 327D - Block Tower 数学题 DFS 初看很难,想通了就感觉很简单

D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After too much playing on paper, Iahub has swi

I will Do iT @ hlyblog.net 1748

【信息科学与工程学】【通信工程】第二百四十篇 IPv4/IPv6 功能点、特性和算法及 IPv4→IPv6 迁移特性02

说明:按「纯数学 → 数学物理 → 多物理场 → 界面/表面科学耦合 + 数学化学 + 运动科学(0.01 nm → μm → mm → cm 精度及超长运动)」纵向穿透,每一行给出,最后挂。

weixin_49199313的博客 509

Windows平台无人机仿真:从零搭建SITL环境与QGC联调

本文详细指导了在Windows平台上从零搭建无人机软件在环(SITL)仿真环境,并与QGroundControl(QGC)进行联调的完整流程。通过使用Cygwin工具链,开发者可以在没有实体硬件的情况下,模拟运行ArduPilot飞控,并通过MAVLink协议连接QGC地面站进行全功能测试,为无人机软件开发提供了一个安全、经济的虚拟沙盒环境。

weixin_29239279的博客 407

cf DP专练

决定每天在codeforces上从2300分以上来一道DP练习 9.8 codeforces 713 C 与poj 3666很像的一道题,这题是严格递增,先考虑非严格递增,容易想到修改后的数字就是原来的子集,所以我们可以定义dp[i][j]表示到第i个数字时,该数字在原来离散化排序后的位置是第j大的 转移就是dp[i][j]=min(dp[i][j],dp[i-1][k]+abs(a[i]-b[k]),1<=k<=j,维护下前缀就是n^2的。下面来到这题,所谓严格递增,我们只需要把a[i]-i即

weixin_45539557的博客 480

手把手教你用AI工具快速开发UniApp首页:从设计稿到完整页面的实战流程

本文详细介绍了如何利用Claude Code、Cursor等AI工具高效开发UniApp首页的完整工作流。从设计稿解析、Prompt工程、代码生成优化到调试适配,提供了一套可复用的实战流程,帮助前端开发者大幅提升从设计到代码的转化效率。

weixin_29199873的博客 317

CF327

A题:Flipping Game 题意:n个数字由0,1组成,一次反转定义为将连续的n个0翻转为1.求经过一次翻转后,1的个数做多是多少??? 很水的一道题,方法就是求出1的个数和连续0个数最多的区间长度。二者相加就是答案~~~ #include #include using namespace std; int main() { int i,n,a,x,y,mx; cin

n a^o7 !的专栏 688

GD32H7 SPI驱动实战:手把手教你用SPI3连接外部Flash(W25Q128)并实现读写

本文详细介绍了基于GD32H7系列MCU的SPI3接口驱动W25Q128外部Flash的全流程开发指南。从硬件设计、引脚配置到SPI3外设深度配置,再到底层通信函数实现和高级功能优化,提供了完整的解决方案。特别针对高速读取、DMA传输和信号完整性等关键环节进行了优化,确保系统在-40℃~85℃范围内稳定工作。

weixin_28729205的博客 379

PSI5协议技术文档与驱动开发指南

• 供电与数据复用:ECU通过双绞线为传感器提供稳压(典型值5V-11V),同时检测线路电流变化实现数据传输。• 同步信号:ECU发送3.5V电压脉冲(上升沿触发传感器响应),用于时序同步。• 安全气囊:PSI5-P模式实现多碰撞传感器同步采样(响应时间<10ms)• CRC-3(3位):ASIL-B以上功能安全要求(如动力总成传感器)• 奇偶校验(1位):适用于低安全等级场景(如PSI5-P10P模式)• 典型应用:PSI5-P(并行总线)、PSI5-U(通用总线)

u012733413的博客 2867

cf 327D Block Tower

After too much playing on paper, Iahub has switched to computer games. The game he plays is called "Block Towers". It is played in a rectangular grid with n rows and m columns (it contains n×m cells

LSS 658

高通8155车机系统里,安卓和QNX是怎么‘打电话’的?聊聊HAB通信框架那些事

本文深入解析了高通8155车机系统中HAB通信框架如何实现安卓与QNX的高效协同。作为异构系统的通信桥梁,HAB通过共享内存和中断信号机制,在多媒体数据传输中展现出零拷贝、硬件加速等优势,成为智能座舱实现实时性与生态丰富性平衡的关键技术。

weixin_42715608的博客 381

CF_327C_MagicFive

Magic Five time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There is a long plate s containing n digits. Iahub wants to

OTTFF的博客 433

异步处理优化:多线程线程池与消息队列的选择与应用

本文讨论了两种常见的异步处理方式:多线程线程池和消息队列(MQ)。通过将非核心逻辑异步化,可以提升系统的性能和响应速度。多线程线程池适用于本地并发任务,适合需要快速响应的场景,但无法处理跨服务任务。消息队列则适用于分布式系统,能够解耦服务并保证任务的可靠性和顺序性,适合处理高并发和高可靠性要求的任务。文章提供了实际代码示例,帮助开发者根据业务需求选择合适的异步处理方式。

曾经“等你生日那天”都遥远得像未来,如今却可欢愉的挥手说“下个十年见” 170万+

QT实现ftp服务器(附完整源码)

QT实现ftp服务器(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 1783

CF 327 130719bnu

A题:给你一串只有0和1的字符串,让你通过使一个区间异或后所得的字符串中1的个数最大。 小结:题目以来没想太多,以为是找最长有多少个0,直接交了一发WA,最后看了下数据,暴力秒过。 代码: #include using namespace std; int sum[105]; int a[105]; int main() { int n; cin>>n; sum[0]

649

【72】【OpenCV C++ & C#】 将cv::Mat 图像转换成imgINFO 传给c#在winform上显示,OpenCV C++如何将处理后的图像传给C#呢? 如何获取图像信息呢?

本文介绍了通过OpenCV C++处理图像后传递给C#的方法。首先定义了一个结构体imgINFO存储图像信息(数据指针、宽高、通道数等),然后通过getImgInfo函数将cv::Mat转换为该结构体。文章特别指出当图像宽度不能被4整除时可能出现失真问题,并给出了两种解决方案:调整输入图像或创建新的对齐图像。此外还解释了img.step和img.cols*img.elemSize()的关系,说明它们在大多数情况下是相等的。最后提到需要通过DLL将结构体传递给C#(具体方法参见其他文章)。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 697

wenbao与cf

选择一个区间反转使得1最多 http://codeforces.com/contest/327/problem/A 弱鸡代码 1 #include <bits/stdc++.h> 2 using namespace std; 3 int sum[120], sum2[120], a[120], b[120]; 4 int main(){ 5 ...

weixin_30869099的博客 145

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

CodeForces ~ 55D ~ Beautiful numbers (数位DP + 离散化)

题意 T次询问,每次循问[L,R]区间内有多少个美丽数字?美丽数字:该数字可以被它各个位上的数字整除。 思路 L~R的美丽数字个数,我们可以转化为1~R的美丽数字个数 减去 1~(L-1)的美丽数字个数 ①该数字可以被它各个位上的数字整除 ②该数字可以被它各个位上的数字的LCM整除,①和②互为充要条件 假设数字xxx是美丽数字,那么x%LCMx=0x%LCMx=0 x\%LCM_x =...

张松超的博客 323

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HDU 4770 Lights Against Dudely

Problem Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money." Hagrid: "Well there's your money, Harry! Gringotts, the wizard bank! Ain't no safer place. Not

左眼皮跳跳 1655

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

HDU 5325 Crazy Bobo(思路+dfs 记忆化)

Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 612    Accepted Submission(s): 189 Problem Description Bobo has a tree,

左眼皮跳跳 1209

hiho一下 第三十周 小Hi小Ho的惊天大作战:扫雷·一

#1114 : 小Hi小Ho的惊天大作战:扫雷·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 故事背景:密室、监视器与充满危机的广场 “我们还是循序渐进,先来考虑这样一个简单化问题:”小Hi思索片刻,道:“在一个大小为2*N的广场,其中第一行里的某一些格子里可能会有至多一个地雷,而第二行的格子里全都为数字,

左眼皮跳跳 1118

poj 1321 棋盘问题(dfs)

Language: Default 棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23127   Accepted: 11478 Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋

左眼皮跳跳 1089

zoj 3811 Untrusted Patrol(dsf+并査集+邻接表)

ZOJ Problem Set - 3811 Untrusted Patrol Time Limit: 3 Seconds      Memory Limit: 65536 KB Edward is a rich man. He owns a large factory for health drink production. As a matter of course,

左眼皮跳跳 1087

HDU 4414 Finding crosses(dfs)

Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in southern Peru. They were designated as a UNESCO World Heritage Site in 1994. The high, arid platea

左眼皮跳跳 1074
上一篇: ZOJ Friends(暴力)
下一篇: POJ 2411 Mondriaan's Dream(状压 dp)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值