链接:https://codeforces.com/contest/1105/problem/D

题意:

给n*m的地图,最多9个人,同时有每个人的扩张次数(我开始以为是直线扩张最大长度。。实际是能连续扩张次数。)

地图上有‘#’,‘.',和数字,数字对应每个人的据点,

从1-n轮流扩张。

地图被扩张完后,输入每个人的据点数目。

思路:

赛后写的题。还一堆bug,

用队列和一个数组,记录每个人能扩张的点和下一次能扩张的个数。

然后就是一堆循环套着。每次入队更新下一次的扩张个数,同时用flag记录有几个人还可以扩张。

不能扩张就减一。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN = 1010;
  4. struct Node
  5. {
  6. int _x;
  7. int _y;
  8. Node(int x,int y):_x(x),_y(y){}
  9. };
  10. int Next[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
  11. int next_time[10];
  12. int Map[MAXN][MAXN];
  13. int number[10];
  14. int speed[10];
  15. int vis[10];
  16. queue<Node> player[10];
  17.  
  18. int main()
  19. {
  20. int n, m, p;
  21. char c;
  22. scanf("%d%d%d", &n, &m, &p);
  23. for (int i = 1; i <= p; i++)
  24. {
  25. scanf("%d", &speed[i]);
  26. }
  27. for (int i = 1; i <= n; i++)
  28. {
  29. for (int j = 1; j <= m; j++)
  30. {
  31. cin >> c;
  32. if (c == '.')
  33. Map[i][j] = 0;
  34. else if (c == '#')
  35. Map[i][j] = -1;
  36. else
  37. {
  38. Map[i][j] = c - '0';
  39. player[c - '0'].push(Node(i, j));
  40. number[c - '0']++;
  41. next_time[c - '0']++;
  42. }
  43. }
  44. }
  45. int flag = p;
  46. while (flag > 0)
  47. {
  48. for (int i = 1; i <= p; i++)
  49. {
  50. if (player[i].empty())
  51. continue;
  52. for (int times = 1; times <= speed[i]; times++)
  53. {
  54. int ti = next_time[i];
  55. next_time[i] = 0;
  56. for (int z = 1; z <= ti; z++)
  57. {
  58. //cout << 2 << endl;
  59. int x = player[i].front()._x;
  60. int y = player[i].front()._y;
  61. player[i].pop();
  62. for (int j = 0; j < 4; j++)
  63. {
  64. int tx = x + Next[j][0];
  65. int ty = y + Next[j][1];
  66. if (tx < 1 || tx > n || ty < 1 || ty > m)
  67. continue;
  68. if (Map[tx][ty] != 0 || Map[tx][ty] == '#')
  69. continue;
  70. Map[tx][ty] = i;
  71. number[i]++;
  72. player[i].push(Node(tx, ty));
  73. next_time[i]++;
  74. }
  75. }
  76. if (player[i].empty()&&vis[i] == 0)
  77. {
  78. flag--;
  79. vis[i] = 1;
  80. break;
  81. }
  82. /*
  83. for (int v = 1;v<=n;v++)
  84. {
  85. for (int c = 1;c<=m;c++)
  86. cout << Map[v][c] << ' ';
  87. cout << endl;
  88. }
  89. */
  90. }
  91. //cout << 3 << endl;
  92. //cout << player[i].size() << endl;
  93. }
  94. if (flag <= 0)
  95. break;
  96. //cout << 4 << endl;
  97. }
  98.  
  99. for (int i = 1; i <= p; i++)
  100. printf("%d ", number[i]);
  101. printf("\n");
  102.  
  103. return 0;
  104. }

  

Codeforces Round #533(Div. 2) D.Kilani and the Game的更多相关文章

  1. Codeforces Round #533 (Div. 2) D. Kilani and the Game(BFS)

    题目链接:https://codeforces.com/contest/1105/problem/D 题意:p 个人在 n * m 的地图上扩展自己的城堡范围,每次最多走 a_i 步(曼哈顿距离),按 ...

  2. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  3. Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS

    题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...

  4. Codeforces Round #533 (Div. 2)

    C: 题意: 有n个整数ai,数列a有两个神奇的性质.1.所有的整数都在[l,r]范围内.2.这n个数的和能被3整除.现在给出l和r,和个数n,问你有多少种方法构造出数列a,方案数mod1e9+7. ...

  5. Codeforces Round #533 (Div. 2) Solution

    A. Salem and Sticks 签. #include <bits/stdc++.h> using namespace std; #define N 1010 int n, a[N ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #533(Div. 2) C.Ayoub and Lost Array

    链接:https://codeforces.com/contest/1105/problem/C 题意: 给n,l,r. 一个n长的数组每个位置可以填区间l-r的值. 有多少种填法,使得数组每个位置相 ...

  9. Codeforces Round #533(Div. 2) B.Zuhair and Strings

    链接:https://codeforces.com/contest/1105/problem/B 题意: 给一个字符串和k,连续k个相同的字符,可使等级x加1, 例:8 2 aaacaabb 则有aa ...

随机推荐

  1. Ubuntu下安装Android studio【转】

    本文转载自:http://blog.csdn.net/walleit/article/details/65696712 版权声明:本文为博主原创文章,未经博主允许不得转载. 一,软件准备 1. Lin ...

  2. HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂

    题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Othe ...

  3. centos 7 / 6 smokeping安装

    官网 值得拥有:http://oss.oetiker.ch/smokeping/doc/reading.en.html 安装依赖包 1 2 yum -y install perl perl-Net-T ...

  4. Jmeter创建一个简单的http接口用例

    1.新建线程组 添加->Threads(Users)->线程组 线程组用来模拟用户进程. 2.添加http信息头管理器 添加->配置元件->http信息头管理器 Systemi ...

  5. 用margin还是用padding?(3)—— 负margin实战

    看过一篇文章是关于我知道你不知道的负Margin,里面对margin做了总结: 当margin四个值都为正数值的话,那么margin按照正常逻辑同周围元素产生边距.当元素margin的top和left ...

  6. Sports

    题目链接 : http://acm.hpu.edu.cn/problem.php?id=1184 或者       http://acm.nyist.net/JudgeOnline/problem.p ...

  7. eclipse Tomcat 启动报错

    如果之前启动都是正常的,更新完后端代码后启动Tomcat报错,又没有错误的日志提示. 尝试先把Tomcat里面的项目删掉,然后点击Tomcat右键,Clean清除缓存,再把项目Add: 重新启动!

  8. CF 622 F The Sum of the k-th Powers —— 拉格朗日插值

    题目:http://codeforces.com/contest/622/problem/F 设 f(x) = 1^k + 2^k + ... + n^k 则 f(x) - f(x-1) = x^k ...

  9. C/C++获取Linux系统CPU和内存及硬盘使用情况

    需求分析: 不使用Top  df  free 等命令,利用C/C++获取Linux系统CPU和内存及硬盘使用情况 实现: //通过获取/proc/stat (CPU)和/proc/meminfo(内存 ...

  10. awk里面执行shell命令

    先把文件列表存在filename文件中 先 awk '{system("rm $0")}' filename -------WRONG 因为对于 system来说 $0 不再是某行 ...