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

[附源码]计算机毕业设计-Steam游戏平台系统论文Springboot程序

项目运行环境配置:(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。项目技术:等等组成,B/S模式 + Maven管理等等。环境需要1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可4.

JSP、ssm毕设程序源码 1494

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

本地部署静态网站托管平台 Netlify 并实现外部访问(Windows 版本)

Netlify 是一款基于云计算的网站部署和托管平台,专为开发者提供便捷的静态网站和 Jamstack 应用部署服务。它的能力在于将网站构建、部署、托管以及持续集成等流程高度集成,简化了开发和运维的复杂程度。用户无需关心服务器的配置、维护等工作。本文将详细介绍如何在本地安装 Netlify 以及结合路由侠内网穿透实现外网访问 Netlify。

lyxnwct的博客 523

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

基于LSTM的多变量温度预测(python从入门到入坑)

基于LSTM的多变量温度预测(python) ——我保证他能够运行,而且结果能够让你满意(如果你和我一样都是一个新手的话) 这里写目录标题基于LSTM的多变量温度预测(python)——我保证他能够运行,而且结果能够让你满意(如果你和我一样都是一个新手的话)一、我为什么要写这些?二、具体做了什么?三、源代码切块加注释,恳请批评指正(●’◡’●)ノ 一、我为什么要写这些? 因为让人抓狂的课程大作业,我小组选择了一个多变量预测方面的课题,在我这个大三基本上还没接触过Python数据处理,甚至对神经网络什么的都

代码之狐的博客 1万+

WIFI基础入门--802.11g--增强速率物理层ERP--15

WIFI基础入门--802.11--增强速率物理层--191.802.11g的组件保护机制 1.802.11g的组件 802.11g其实是将好几种物理层规范合而为一。虽然统称为增强速率物理层(Extended Rate PHY简称ERP),但是实际上ERP有好几种不同的方式: ERP-DSSS与ERP-CCK 这两种模式向下兼容于原始直接序列规范(1Mbps与2Mbps),以及所提到的802.11...

香蕉一号 4617

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

8、干式变压器

干式变压器的发展,是人类不断挑战材料科学和热物理极限的过程,每一次技术突破,都是在。温度升高,ε_r反而下降(因为分子活动性增强,极化响应变慢)。:固体导热的热阻比液体对流大一个数量级,这是无法逾越的物理规律。Nomex在高温下不是逐渐分解,而是保持性能直到一个临界点。如果 T_a = 40°C,则 T_c = 146.7°C。干式变压器(固体介质分隔):热场、电场、流场(空气)形成三维氢键网络,即使在高温下也能保持机械强度。:不是在现有技术上修修补补,而是寻找新的。仍在H级绝缘允许范围内(≤180°C)

renpeng2692873032的博客 228

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

X书关键词协议搜索

【代码】X书关键词协议搜索。

Codeooo 博客 6377

LPDDR6与LPDDR5 ZQ Calibration技术探讨

LPDDR6与LPDDR5 ZQ Calibration技术探讨

zilan23的博客 1098

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

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

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

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

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、付费专栏及课程。

余额充值