CoderForces 327D Block Tower
Portal:http://codeforces.com/problemset/problem/327/D
一座红塔200人,一座蓝塔100人,只有与蓝塔相邻才可以建红塔。
'.'处可建塔 '#'处不可建塔
可以随便毁塔
在建造能够容纳最多人数的塔集合情况下,输出对塔的操作(SPJ)
这是一道水题
这是一道卡输入输出的题
DFS就好,反正就是在联通分量里炸割顶留根
#include<iostream>
#include<algorithm>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
#define SZ(x) int(x.size())
#define maxm 510
#define maxn 510
string x;
int dx[]={,,-,};
int dy[]={,,,-};
int m,n,sum;
vector<char> al;
vector<int> ax,ay;
char ii[maxm][maxn];
int a[maxm][maxn],vis[maxm][maxn],col[maxm][maxn];
bool cr(int xx,int yy)
{
FOR(i,,)
if(xx+dx[i]>&&xx+dx[i]<=m&&yy+dy[i]>&&yy+dy[i]<=n)
if(col[xx+dx[i]][yy+dy[i]]==) return true;
return false;
}
void dfs(int x,int y)
{
vis[x][y]=;
/*if(cr(x,y)) {al.push_back('R');ax.push_back(x);ay.push_back(y);col[x][y]=2;sum++;}
else */{al.push_back('B');ax.push_back(x);ay.push_back(y);col[x][y]=;sum++;}
FOR(i,,)
if(x+dx[i]>&&x+dx[i]<=m&&y+dy[i]>&&y+dy[i]<=n)
if(a[x+dx[i]][y+dy[i]]) if(!vis[x+dx[i]][y+dy[i]]) dfs(x+dx[i],y+dy[i]);
if(col[x][y]==) if(cr(x,y)) { al.push_back('D');ax.push_back(x);ay.push_back(y);
al.push_back('R');ax.push_back(x);ay.push_back(y);col[x][y]=;sum+=;}
}
int main()
{
cin>>m>>n;
FOR(i,,m)
{scanf("%s",&ii[i][]);
FOR(j,,n)
{
a[i][j]=(ii[i][j]=='.');
}
}
FOR(i,,m)
FOR(j,,n)
if(a[i][j]&&!vis[i][j]) dfs(i,j);
cout<<sum<<endl;
FOR(i,,SZ(al)-)
printf("%c %d %d\n",al[i],ax[i],ay[i]);
return ;
}
特别丑的原代码(AC)
#include<iostream>
#include<algorithm>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<sstream>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
#define SZ(x) int(x.size())
#define maxm 510
#define maxn 510
char x;
stringstream ans;
int dx[]={,,-,};
int dy[]={,,,-};
int m,n,sum;
char ii[maxm][maxn];
int a[maxm][maxn],vis[maxm][maxn],col[maxm][maxn];
bool cr(int xx,int yy)
{
FOR(i,,)
if(xx+dx[i]>&&xx+dx[i]<=m&&yy+dy[i]>&&yy+dy[i]<=n)
if(col[xx+dx[i]][yy+dy[i]]==) return true;
return false;
}
void dfs(int x,int y)
{
vis[x][y]=;
ans<<"B "<<x<<' '<<y<<"\n";col[x][y]=;sum++;
FOR(i,,)
if(x+dx[i]>&&x+dx[i]<=m&&y+dy[i]>&&y+dy[i]<=n)
if(a[x+dx[i]][y+dy[i]]) if(!vis[x+dx[i]][y+dy[i]]) dfs(x+dx[i],y+dy[i]);
if(col[x][y]==) if(cr(x,y)) { ans<<"D "<<x<<' '<<y<<"\n";
ans<<"R "<<x<<' '<<y<<"\n";col[x][y]=;sum+=;}
}
int main()
{
cin>>m>>n;
FOR(i,,m)
FOR(j,,n)
{
cin>>x;
a[i][j]=(x=='.');
}
FOR(i,,m)
FOR(j,,n)
if(a[i][j]&&!vis[i][j]) dfs(i,j);
cout<<sum<<endl;
cout<<ans.str();
return ;
}
改后依然很丑的代码
输出黑科技sstream orz
#include<sstream> x;
x<<.....;
cout<<x.str();
输入黑科技
scanf("%s",&string[i][]);

CoderForces 327D Block Tower的更多相关文章
- CF 327D - Block Tower 数学题 DFS 初看很难,想通了就感觉很简单
D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CodeForces - 327D Block Tower
D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #191 (Div. 2) D. Block Tower
D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 2013/7/16 HNU_训练赛4
CF328B Sheldon and Ice Pieces 题意:给定一个数字序列,问后面的数字元素能够组成最多的组数. 分析:把2和5,6和9看作是一个元素,然后求出一个最小的组数就可以了. #in ...
- CF 191 总结
A. Flipping Game 链接:http://codeforces.com/contest/327/problem/A 题意:从 i 到 j 翻转一次使得 1 的 个数最多~ 直接暴力搞~ # ...
- Codeforces Round #191 (Div. 2)
在div 188中,幸运的达成了这学期的一个目标:CF1800+,所以这次可以打星去做div2,有点爽. A.Flipping Game 直接枚举 B. Hungry Sequence 由于素数的分布 ...
- [Swust OJ 893]--Blocks
题目链接:http://acm.swust.edu.cn/problem/893/ Time limit(ms): 1000 Memory limit(kb): 65535 Josh loves ...
- UVa 437 The Tower of Babylon(经典动态规划)
传送门 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details ...
- UVa 437 The Tower of Babylon
Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of ...
随机推荐
- 在浏览器中使用ES6的模块功能 import 及 export
感谢英文原作者 Jake Archibald 的技术分享 各个浏览器对于ES6模块 import . export的支持情况 Safari 10.1. Chrome 61. Firefox 54 – ...
- LeetCode 33.Search in Rotated Sorted Array(M)
题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ( ...
- C/C++ 手动开O2
手动O2比赛不能用,平时玩玩就好 #pragma GCC optimize (2) #pragma G++ optimize (2)
- 【猫狗数据集】利用tensorboard可视化训练和测试过程
数据集下载地址: 链接:https://pan.baidu.com/s/1l1AnBgkAAEhh0vI5_loWKw提取码:2xq4 创建数据集:https://www.cnblogs.com/xi ...
- 树莓派3b+ 交叉编译 及升级 kernel
安装 gcc pkg 等工具sudo apt-get install build-essential git 官方介绍 https://www.raspberrypi.org/documentatio ...
- vue 父子组件 基础应用scrollball v-model sync
# 组件之间通信 可以通过 v-model 子组件可以通过 改变数据来改变父组件的数组 * v-model 子组件需要接受value属性,需要出发this.$emit("input&qu ...
- 五分钟完成 ABP vNext 通讯录 App 开发
五分钟完成 ABP vNext 通讯录 App 开发 ABP vNext(后文简称Abp)是 Volo 公司堪称艺术品级的应用开发框架,它基于领域驱动设计(DDD)的思维,创新地采用了模块化的设计.A ...
- 【牛客】乃爱与城市拥挤程度 — 树形dp,up and down
我太难了 这题做得我要死了,来来回回写了大概八九个小时 错误的原因要么是快速幂写错(一生之敌,要么是忘取模爆\(longlong\)变负数\(QAQ\) \(update\) \(2019.11.13 ...
- react 装 router - yarn add react-router-dom@next
react 装 router yarn add react-router-dom@next
- 一段很简单的PHP代码,用于手机拨号
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...