Codeforces Round #533(Div. 2) D.Kilani and the Game
链接:https://codeforces.com/contest/1105/problem/D
题意:
给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度。。实际是能连续扩张次数。)
地图上有‘#’,‘.',和数字,数字对应每个人的据点,
从1-n轮流扩张。
地图被扩张完后,输入每个人的据点数目。
思路:
赛后写的题。还一堆bug,
用队列和一个数组,记录每个人能扩张的点和下一次能扩张的个数。
然后就是一堆循环套着。每次入队更新下一次的扩张个数,同时用flag记录有几个人还可以扩张。
不能扩张就减一。
代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
struct Node
{
int _x;
int _y;
Node(int x,int y):_x(x),_y(y){}
};
int Next[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int next_time[10];
int Map[MAXN][MAXN];
int number[10];
int speed[10];
int vis[10];
queue<Node> player[10]; int main()
{
int n, m, p;
char c;
scanf("%d%d%d", &n, &m, &p);
for (int i = 1; i <= p; i++)
{
scanf("%d", &speed[i]);
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> c;
if (c == '.')
Map[i][j] = 0;
else if (c == '#')
Map[i][j] = -1;
else
{
Map[i][j] = c - '0';
player[c - '0'].push(Node(i, j));
number[c - '0']++;
next_time[c - '0']++;
}
}
}
int flag = p;
while (flag > 0)
{
for (int i = 1; i <= p; i++)
{
if (player[i].empty())
continue;
for (int times = 1; times <= speed[i]; times++)
{
int ti = next_time[i];
next_time[i] = 0;
for (int z = 1; z <= ti; z++)
{
//cout << 2 << endl;
int x = player[i].front()._x;
int y = player[i].front()._y;
player[i].pop();
for (int j = 0; j < 4; j++)
{
int tx = x + Next[j][0];
int ty = y + Next[j][1];
if (tx < 1 || tx > n || ty < 1 || ty > m)
continue;
if (Map[tx][ty] != 0 || Map[tx][ty] == '#')
continue;
Map[tx][ty] = i;
number[i]++;
player[i].push(Node(tx, ty));
next_time[i]++;
}
}
if (player[i].empty()&&vis[i] == 0)
{
flag--;
vis[i] = 1;
break;
}
/*
for (int v = 1;v<=n;v++)
{
for (int c = 1;c<=m;c++)
cout << Map[v][c] << ' ';
cout << endl;
}
*/
}
//cout << 3 << endl;
//cout << player[i].size() << endl;
}
if (flag <= 0)
break;
//cout << 4 << endl;
} for (int i = 1; i <= p; i++)
printf("%d ", number[i]);
printf("\n"); return 0;
}
Codeforces Round #533(Div. 2) D.Kilani and the Game的更多相关文章
- Codeforces Round #533 (Div. 2) D. Kilani and the Game(BFS)
题目链接:https://codeforces.com/contest/1105/problem/D 题意:p 个人在 n * m 的地图上扩展自己的城堡范围,每次最多走 a_i 步(曼哈顿距离),按 ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Codeforces Round #533 (Div. 2)
C: 题意: 有n个整数ai,数列a有两个神奇的性质.1.所有的整数都在[l,r]范围内.2.这n个数的和能被3整除.现在给出l和r,和个数n,问你有多少种方法构造出数列a,方案数mod1e9+7. ...
- Codeforces Round #533 (Div. 2) Solution
A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...
- Codeforces Round #533 (Div. 2) C. Ayoub and Lost Array 【dp】
传送门:http://codeforces.com/contest/1105/problem/C C. Ayoub and Lost Array time limit per test 1 secon ...
- Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模拟】
传送门:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1 second ...
- Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...
- Codeforces Round #533(Div. 2) B.Zuhair and Strings
链接:https://codeforces.com/contest/1105/problem/B 题意: 给一个字符串和k,连续k个相同的字符,可使等级x加1, 例:8 2 aaacaabb 则有aa ...
随机推荐
- 原来 Set 集合也可以排序
Java 集合类主要由两个接口派生而出: Collection 和 Map.在 Collection 集合中,我们经常用到的是 List 集合和 Map 集合,而 Set 集合出场的机会就相对比较的少 ...
- python 实用pickle序列化
存储数据结构到一个文件中称为序列化.相json这样的格式需要定制的序列化数据的转换器.python提供了pickle模块以特殊的二进制格式保存和恢复数据对象. 还记得json解析datetime对象时 ...
- git 合并子分支
1.子分支 $ git status 位于分支 base 无文件要提交,干净的工作区 2.子分支更新 $ git pull origin base 来自 http://106.14.59.204/ji ...
- ssh整合 小例子
实现了用户的查插删改操作. 原理:struts负责接收.分发请求.spring采用面向接口编程的思想整合整体框架,负责连接数据库.hibernate负责操作数据库语言. 思路: 1.配置struts的 ...
- SSL handshake_decode_error
查看布署在Amazon服务器上的日志时,发现如下错误: generated SERVER ALERT: Fatal - Handshake Failure - handshake_decode_err ...
- Mac的环境变量
在终端输入: vim ~/.bash_profile 按i切换到INSERT模式.然后把路径按照下面的格式写进去.然后输入:wq保存退出. export PATH=${PATH}:/Users/Dru ...
- bzoj 4712 洪水 —— 动态DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4712 设 f[x] = min(∑f[u] , a[x]),ls = ∑f[lson] 矩阵 ...
- poj3565Ants——KM算法
题目:http://poj.org/problem?id=3565 首先,我们神奇地发现,没有相交边的匹配可以转化为距离和最小的匹配,所以可以使用KM算法求带权匹配: 要求的是距离和最小,所以把边权转 ...
- JAVA 内部类 (二)
一.为什么要使用内部类 为什么要使用内部类?在<Think in java>中有这样一句话:使用内部类最吸引人的原因是:每个内部类都能独立地继承一个(接口的)实现,所以无论外围类是否已经继 ...
- bzoj1195
AC自动机+状压dp 多串匹配要想ac自动机 dp[i][S]表示在i状态选中S 转移就用bfs,每个点通过fail收集信息,不要忘记通过fail传递 昨天搞不明白为什么自动机每次只可以转移儿子,不可 ...