#1392 : War Chess

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

Rainbow loves to play kinds of War Chess games. There are many famous War Chess games such as "Biography of Cao Cao", "Anecdotes of Wagang Mountain", etc. In this problem, let's consider a much simpler version of War Chess games. The game is based on the following features:

MAP

The map is a rectangular area which consists of N rows and M columns. The cells in the rectangular area have various landforms like plain, woods, hill, river, snowfield, etc. Specifically, each cell (i,j) is assigned an integer of moving property Gi,j, which makes influence on going across it.

CHARACTER

A character can be regarded as a person standing in a cell of the map. Each character has life HP, attacking ability AT, moving ability MV and attacking distance range [AD1,AD2]. Characters are divided into two groups. Group 0 is controlled by the player and group 1 is controlled by the system.

A character can attack a character from the opposite group if the Manhattan distance between them is in the attacker's attacking distance range (inclusive).  When a character p is attacked by enemy q, its life HPp will be minus by ATq. A character is driven out of the map immediately when its HP becomes 0 or negative.

Each character can occupy a cell or move on the map. Several rules specify the position and moving limits of them:

OCCUPATION

Initially, characters are generated in different cells. They occupy their own cell separately. A character cannot move when another one is moving.

Once a character starts to move, it will lose occupation of its current standing cell. When the character stops moving, it will gain the occupation of the cell it is standing in.

STEP

A move consists of several steps. Each step, one can walk from a cell to an adjacent cell sharing an edge (up, down, left or right). A step walking to a cell occupied by the other character is invalid.

When it steps from a cell (i,j) to a cell (x,y), its moving ability MV will be minus by Gx,y. Moving steps which make MV become negative are invalid. After a valid step, if the current cell is beside (sharing an edge with) someone of the opposite group, the MV of a character will become 0.

A character's MV recovers to the original value immediately when it gains occupation of a cell.

The set of cells, able to be reached by valid steps and stopped at in a move, is called a character’s moving range. Staying at the original cell is also valid and should be counted into the moving range.

The process of the game contains several rounds. In each round, the player's group acts first and the system's group acts next. For each group, the characters of the group act by turns. In each action, a character first moves to a cell in its moving range, then attacks a character of the opposite group in its attacking distance range or do nothing. When all the characters of a group are driven out of the map, the group loses the game and the opposite group wins.

Rainbow has just got some logs of a game and wants to watch the game. Help him to recover the game process.

输入

There are multiple test cases (no more than 20). For each test case:

The first line contains three integers N,M,C,E (1≤N,M≤100,2≤C≤min(N*M,100),1≤E≤3000), representing the number of rows and columns, the number of characters and the number of events in the log.

Each of the next N lines contains M integers, representing the moving property Gi,j (1≤Gi,j≤102 ).

Each of the next C lines contains eight integers HP, AT, MV, AD1, AD2, STx, STy, GR,(1≤HP,AT,MV≤103,1≤AD1≤AD2≤20,1<STx≤N,1≤STy≤M,0≤GR≤1), representing the five properties, the initial position and the group of a character.

The next E lines describe events in the log. Each line is in one of the following formats:

Round of GR – Characters in group GR take the round.

Action of character ID – Character ID takes the action.

Move to (x,y) – Current acting character moves to cell (x,y) by some steps.

Attack ID – Current acting character attacks character ID but ID isn’t driven out.

Drive out ID – Current acting character attacks character ID and ID is driven out.

In the events, 1≤x≤N,1≤y≤M,1≤ID≤C,0≤GR≤1. The row number of cells is marked 1 to N from top to bottom, the column number is marked 1 to M from left to right. Initially, each group has at least one character.

输出

For each event of Move to, output "INVALID" if breaking the moving rules. Otherwise output the maximum rest moving ability when it stepped into the destination.

For each event of Attack or Drive out, output "INVALID" if cannot attack or being wrong at driving out. Otherwise, output the remaining HP of the one being attacked.

Invalid events should be ignored while dealing with the next events. The data ensures that the game has just finished after processing all the valid events. Events of Round of and Action of are ensured to be well recorded in the log without missing or breaking.

样例输入
  1. 5 5 4 12
  2. 1 9 1 4 4
  3. 1 9 1 2 4
  4. 1 9 1 1 2
  5. 2 9 2 7 3
  6. 2 3 2 6 1
  7. 10 5 8 1 3 1 1 0
  8. 20 10 5 1 2 2 1 0
  9. 19 10 5 1 2 5 2 1
  10. 25 25 3 1 1 5 5 0
  11. Round of 0
  12. Action of character 2
  13. Move to (5,1)
  14. Attack 3
  15. Action of character 1
  16. Move to (3,1)
  17. Round of 1
  18. Action of character 3
  19. Drive out 1
  20. Round of 0
  21. Action of character 2
  22. Drive out 3
样例输出
  1. 0
  2. 9
  3. 6
  4. INVALID
  5. -1

题目链接:

  http://hihocoder.com/problemset/problem/1392

题目大意:

  N*M的地图,C个游戏角色,E个操作。(1≤N,M≤100,2≤C≤min(N*M,100),1≤E≤3000)

  地图上为经过这个位置需要消耗的移动值G[i,j]。游戏角色分为两个阵营,Group0由玩家控制,Group1由系统控制。每个角色有几个属性:

  HP血量, AT为攻击力,MV为移动值,AD1和AD2为角色的攻击范围(曼哈顿距离),X和Y为角色初始位置,Group为角色所属阵营。

  一开始每个玩家都会占领一个格子,每个人的格子都互不相同。每次只能有一个玩家在移动。如果一个玩家开始移动,那么之前占领的格子会被释放,停止移动后,占领现在的格子。

  每次移动可以走多步,经过的地方要扣除G,不能走到已经有角色的位置,在行动过程中MV值不能小于0,如果走到当前组的敌方周围(上下左右)则不能再移动,但是在停下之后下一次行动时MV恢复到初始值。

  如果角色A攻击角色B可行则角色B的HP-角色A的AT。如果角色B死亡则立即移除出游戏。

  游戏开始后,两个Group轮流操作,先Group0后Group1。选取角色后角色移动到一个位置(不移动也可以),然后攻击某个敌人(不攻击也可以)。当一个Group的角色都死掉后,游戏结束。

  现在已知一次游戏的操作,求还原游戏场景。

  

  E个操作,操作分几种:

  Round of X – 现在轮到GroupX 行动,X为0,1。保证合法

  Action of character ID – 角色ID开始行动。保证合法

  Move to (x,y) – 当前角色移动到(x,y)位置。如果合法输出最大的剩余移动值,否则输出INVALID

  Attack ID – 当前角色攻击ID角色且角色不死。如果合法输出被攻击角色剩余HP,否则输出INVALID

  Drive out ID – 当前角色攻击ID角色且将ID杀死。如果合法输出被攻击角色剩余HP(负),否则输出INVALID

题目思路:

  【模拟】

  根据题意慢慢模拟就能AC。。比赛差几秒没交上去。赛后AC了。

  Move操作就是简单BFS,判断当前能走的格子是否越界,上面有没人,是否是敌方周围的。

  Attack操作就判断两个人的曼哈顿距离是否在攻击范围内,ID的剩余HP是否大于0,Drive out操作判断是否<=0。

  还有就是不能攻击友军,已经死的人等等细节。注意一下。

  

  1. //
  2. //by coolxxx
  3. //#include<bits/stdc++.h>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<string>
  7. #include<iomanip>
  8. #include<map>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #include<bitset>
  13. #include<memory.h>
  14. #include<time.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17. #include<string.h>
  18. //#include<stdbool.h>
  19. #include<math.h>
  20. #define min(a,b) ((a)<(b)?(a):(b))
  21. #define max(a,b) ((a)>(b)?(a):(b))
  22. #define abs(a) ((a)>0?(a):(-(a)))
  23. #define lowbit(a) (a&(-a))
  24. #define sqr(a) ((a)*(a))
  25. #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
  26. #define mem(a,b) memset(a,b,sizeof(a))
  27. #define eps (1e-10)
  28. #define J 10000
  29. #define mod 1000000007
  30. #define MAX 0x7f7f7f7f
  31. #define PI 3.14159265358979323
  32. #pragma comment(linker,"/STACK:1024000000,1024000000")
  33. #define N 104
  34. using namespace std;
  35. typedef long long LL;
  36. double anss;
  37. LL aans;
  38. int cas,cass;
  39. int n,m,lll,ans;
  40. int ro,person,Aperson,sx,sy,ex,ey;
  41. int g[N][N],d[N][N],mark[N][N];
  42. bool u[N][N];
  43. int dx[]={-,,,};
  44. int dy[]={,,-,};
  45. struct xxx
  46. {
  47. int HP,AT,MV,D1,D2,X,Y;
  48. bool G,dead;
  49. }a[N];
  50. char ss[];
  51. void Round()
  52. {
  53. scanf("%s%d",ss,&ro);
  54. }
  55. void Action()
  56. {
  57. scanf("%s%s%d",ss,ss,&person);
  58. if(a[person].dead || a[person].G!=ro)puts("INVALID");
  59. }
  60. void bfs()
  61. {
  62. queue<int>q;
  63. int i,j,x,y,xx,yy;
  64. q.push(sx),q.push(sy);
  65. mem(d,MAX);mem(mark,);
  66. d[sx][sy]=;
  67. for(i=;i<=cas;i++)
  68. {
  69. if(a[i].dead)continue;
  70. mark[a[i].X][a[i].Y]=;
  71. if(a[i].G!=ro)
  72. {
  73. for(j=;j<;j++)
  74. {
  75. if(mark[a[i].X+dx[j]][a[i].Y+dy[j]]==)
  76. mark[a[i].X+dx[j]][a[i].Y+dy[j]]=;
  77. }
  78. }
  79. }
  80. while(!q.empty())
  81. {
  82. x=q.front(),q.pop();
  83. y=q.front(),q.pop();
  84. if(d[x][y]>a[person].MV)continue;
  85. u[x][y]=;
  86. for(j=;j<;j++)
  87. {
  88. xx=x+dx[j],yy=y+dy[j];
  89. if(xx< || xx>n || yy< || yy>m)continue;
  90. if(mark[xx][yy]==)continue;
  91. if(d[x][y]+g[xx][yy]<=a[person].MV)
  92. {
  93. if(mark[xx][yy]==)
  94. d[xx][yy]=a[person].MV;
  95. else if(d[xx][yy]>d[x][y]+g[xx][yy])
  96. {
  97. d[xx][yy]=d[x][y]+g[xx][yy];
  98. if(u[xx][yy])continue;
  99. u[xx][yy]=;
  100. q.push(xx),q.push(yy);
  101. }
  102. }
  103. }
  104. }
  105. if(d[ex][ey]==MAX)
  106. puts("INVALID");
  107. else
  108. {
  109. printf("%d\n",a[person].MV-d[ex][ey]);
  110. a[person].X=ex,a[person].Y=ey;
  111. }
  112. }
  113. void Move()
  114. {
  115. scanf("%s (%d,%d)",ss,&ex,&ey);
  116. sx=a[person].X,sy=a[person].Y;
  117. bfs();
  118. }
  119. void Attack()
  120. {
  121. scanf("%d",&Aperson);
  122. if(abs(a[person].X-a[Aperson].X)+abs(a[person].Y-a[Aperson].Y)<=a[person].D2
  123. && abs(a[person].X-a[Aperson].X)+abs(a[person].Y-a[Aperson].Y)>=a[person].D1
  124. && a[person].G!=a[Aperson].G && !a[Aperson].dead && Aperson<=cas)
  125. {
  126. if(a[person].AT<a[Aperson].HP)
  127. {
  128. a[Aperson].HP-=a[person].AT;
  129. printf("%d\n",a[Aperson].HP);
  130. }
  131. else
  132. {
  133. puts("INVALID");
  134. }
  135. }
  136. else puts("INVALID");
  137. }
  138. void Drive()
  139. {
  140. scanf("%s%d",ss,&Aperson);
  141. if(abs(a[person].X-a[Aperson].X)+abs(a[person].Y-a[Aperson].Y)<=a[person].D2
  142. && abs(a[person].X-a[Aperson].X)+abs(a[person].Y-a[Aperson].Y)>=a[person].D1
  143. && a[person].G!=a[Aperson].G && !a[Aperson].dead && Aperson<=cas)
  144. {
  145. if(a[person].AT>=a[Aperson].HP)
  146. {
  147. a[Aperson].HP-=a[person].AT;
  148. a[Aperson].dead=;
  149. printf("%d\n",a[Aperson].HP);
  150. }
  151. else
  152. {
  153. puts("INVALID");
  154. }
  155. }
  156. else puts("INVALID");
  157. }
  158. int main()
  159. {
  160. #ifndef ONLINE_JUDGEW
  161. // freopen("1.txt","r",stdin);
  162. // freopen("2.txt","w",stdout);
  163. #endif
  164. int i,j,k;
  165. int x,y,z;
  166. // init();
  167. // for(scanf("%d",&cass);cass;cass--)
  168. // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
  169. // while(~scanf("%s",s))
  170. while(~scanf("%d",&n))
  171. {
  172. scanf("%d%d%d",&m,&cas,&cass);
  173. for(i=;i<=n;i++)
  174. for(j=;j<=m;j++)
  175. scanf("%d",&g[i][j]);
  176. for(i=;i<=cas;i++)
  177. {
  178. scanf("%d%d%d%d%d%d%d%d",&a[i].HP,&a[i].AT,&a[i].MV,&a[i].D1,&a[i].D2,&a[i].X,&a[i].Y,&a[i].G);
  179. a[i].dead=;
  180. }
  181. while(cass--)
  182. {
  183. scanf("%s",ss);
  184. if(!strcmp(ss,"Round"))Round();
  185. else if(!strcmp(ss,"Action"))Action();
  186. else if(!strcmp(ss,"Move"))Move();
  187. else if(!strcmp(ss,"Attack"))Attack();
  188. else if(!strcmp(ss,"Drive"))Drive();
  189. }
  190. }
  191. return ;
  192. }
  193. /*
  194. //
  195.  
  196. //
  197. */

hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)的更多相关文章

  1. hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...

  2. hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...

  3. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job

    描述 Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute ...

  4. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List

    描述 The history of Peking University Library is as long as the history of Peking University. It was b ...

  5. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  6. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

  7. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  8. hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...

  9. hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】

    https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...

随机推荐

  1. IIS7保存配置文件及导入、导出、备份、还原

    IIS6下想要保存配置,只需在图形界面下点右键保存即可,但windows 2008下的IIS7却没有这样的选项, IIS7的配置文件有好几个,在c:\windows\system32\inetsrv\ ...

  2. MVC ViewEngine视图引擎解读及autofac的IOC运用实践

    MVC 三大特色  Model.View.Control ,这次咱们讲视图引擎ViewEngine 1.首先看看IViewEngine接口的定义 namespace System.Web.Mvc { ...

  3. 开源的Android开发框架-------PowerFramework使用心得(五)网络请求HTTPRequest

    GET请求示例 //所有参数都使用Bundle,用putString Bundle bundle = new Bundle(); bundle.putString("username&quo ...

  4. CentOS 7设置iptables防火墙开放proftpd端口

    由于ftp的被动模式是这样的,客户端跟服务器端的21号端口交互信令,服务器端开启21号端口能够使客户端登录以及查看目录.但是ftp被动模式用于传输数据的端口却不是21,而是大于1024的随机或配置文件 ...

  5. Spring中的创建与销毁

    在bean中添加属性init-method="方法名" destroy-method="方法名" init-method        该方法是由spring容 ...

  6. helloServlet

    创建第一个web程序 用myeclipse创建一个web项目,继而创建一个servlet 自动帮助你创建了一个web.xml文件 <servlet>....<servlet>指 ...

  7. php中文乱码

    一.         首先是PHP网页的编码 1.     php文件本身的编码与网页的编码应匹配 a.     如果欲使用gb2312编码,那么php要输出头:header(“Content-Typ ...

  8. ios开发之ios9UIWebView不显示网页问题

    错误描述: App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecu ...

  9. 如何学习YII

    我是在Yii的官方wiki上看到这篇文章的.读的第一遍觉得很不错,还有一种想翻译出来的冲动.虽然,本人英文很烂,但是毕竟写了这样多年的代码,估计大概的意思是能有的吧.英文原文:http://www.y ...

  10. oe 仓库管理

    需求情景: 销售电商, 其中有些产品 为代理销售(公司不管理库存,建立SO后直接由对应的供应商发货即可) 解决方案: SO 生成 DO 时候 , 源库存的取得逻辑        SO-->SHO ...