A. Advanced 2048
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Only lazy did not play the 2048 game last year. Soon, the secret of success had been revealed and interest to the game has faded. Nevertheless, the developers are now working on new modifications to the game. One of the prominent directions for the future development was the increased size of the game field and the increased final score.

However, in order to pick the optimal field size, it is required to emulate the gameplay many times on the fields of different sizes to estimate the number of moves needed to reach the goal under new conditions, and also to estimate the possible score values.

You are to write a program that will determine the final score given the description of a game session: field size, placement of the tiles and their values, the sequence of the player's moves and the description of all new tiles appearing on the field.

For those who are newbies to the popular game, the game rules are the following. 2048 is played on a N × N tile grid, with numbered tiles that all slide when a player moves them using the four arrow keys. After every turn, a new tile will randomly appear in an empty spot on the board with a value of either 2 or 4. Tiles slide as far as possible in the chosen direction until they are stopped by either another tile or the edge of the grid. If two tiles of the same number collide while moving, they will merge into a tile with the total value of the two tiles that collided. The resulting tile cannot merge with another tile again in the same move. The tile moves and mergers are resolved from the first tile to the last one (in terms of movement direction) consequently. For example, after moving to the right, the row "2 2 _ 2 _" turns into "_ _ _ 2 4", and the row "2 2 2 2 2 2" turns into "_ _ _ 4 4 4".

The player's score starts at zero, and is incremented whenever two tiles combine by the value of the new tile.

Input

The first line of input contains an integer N, the size of the field (4 ≤ N ≤ 100). The second line of input contains an integer K, the number of tiles already on the field (0 ≤ K ≤ N2). In each of the next K lines, three integers are given to describe the tiles on the field: a number written in the tile (one of the powers of two from first (2) to tenth (1024)) and the tile coordinates on the field: row and column. Rows are numbered from one starting from the top, and columns are numbered from one starting from the left. It is guaranteed that the given tiles occupy K different cells of the grid.

After that, an integer L is given on a separate line: the number of player's moves in a game session (0 ≤ L ≤ 10 000). The next L lines contain descriptions of the player's moves in their order, one description per line. A description of a move starts with one of the characters "L" (left), "R" (right), "U" (up) or "D" (down). Then follow three integers separated by single spaces. They define the new tile that appeared on the field after the player's move with the value of either 2 or 4 and the coordinates of the tile: row and column. It is guaranteed that the new tile is placed on an empty tile of the field after each player's move.

Output

Output a single integer: the final score in the game which is described in the input.

Sample test(s)
input
6
5
2 1 2
2 1 3
4 1 5
4 1 6
2 3 1
2
L 4 2 1
U 2 6 2
output
20
input
4
4
1024 1 1
1024 1 2
1024 2 1
1024 2 2
2
D 4 1 1
R 4 1 1
output
8192

题意:模拟一下2048的程序,问最后的分值。
分析:模拟

2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest A. Advanced 2048的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)

    2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic 题意:有一张图,第i个点被占领需要ai个兵,而每个兵传送至该 ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  5. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉

    Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...

  6. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题

    Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...

  7. 2016-2017 ACM-ICPC, NEERC, Moscow Subregional Contest Problem L. Lazy Coordinator

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229511 时间限制:1s 空间限制:512MB 题目大意: 给定一个n 随后跟着2n行输入 ...

  8. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  9. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

随机推荐

  1. 方法重载的小demo

    方法的重载(overload)要求:1,同一个类中2,方法名必须相同3,方法的参数列表不同(1,参数的个数不同2,参数类型不同,但是参数名相同) 注:方法的重载与方法的返回值类型没有关系 packag ...

  2. htnl中的遮罩层以及定位方式

    在页面显示遮罩层,例如:一个div的css样式: $msk.css({ "top":"0", "left":"0", & ...

  3. CLR via C#(10)-参数

    一. 命名参数.可选参数 命名参数和可选参数是在Visual C#2010中引入的新特性. 笨地儿我个瓜不兮兮的,今天才知道. 可选参数:定义方法时为参数设置默认值,调用该方法时可以省略为某些形参指定 ...

  4. git中使用.gitignore文件

    在进行协作开发代码管理的过程中,常常会遇到某些临时文件.配置文件.或者生成文件等,这些文件由于不同的开发端会不一样,如果使用git add . 将所有文件纳入git库中,那么会出现频繁的改动和push ...

  5. linux脚本编程技术

    linux脚本编程技术 一.什么是脚本 脚本是一个包含一系列命令序列的可执行(777)文本文件.当运行这个脚本文件时,文件中包含的命令序列将得到自动执行. 二.脚本编程 #!/bin/sh 首行固定格 ...

  6. windows OBJECT查找

    PspCidTable表里.索引值总之4的倍数.也就是说 PID/4 才是PspCidTable索引.*8 才是PsPCidTable+偏移.获取进程对应的 _HANDLE_TABLE_ENTRY 结 ...

  7. jQuery基础知识点(DOM操作)

    1.样式属性操作     1)设置样式属性操作         ①设置单个样式: // 第一个参数表示:样式属性名称 // 第二个参数表示:样式属性值 $(selector).css(“color”, ...

  8. FreeMarker学习(宏<#macro>的使用)

    原文链接:https://my.oschina.net/weiweiblog/blog/506301?p=1 用户定义指令-使用@符合来调用  有两种不同的类型:Macro(宏)和transform( ...

  9. Java中引用类 strong reference .SoftReference 、 WeakReference 和 PhantomReference的区别

      当在 Java 2 平台中首次引入 java.lang.ref 包,其中包含 SoftReference . WeakReference 和 PhantomReference 三个引用类,引用类的 ...

  10. 【java基础】选择排序and冒泡排序

    前言 : 今天学习的是J2SE视频里的第五章,数组部分,它里面留了一个经典的作业,就是让我们去从1倒9按一定规格排序,这让我想起了学习vb的时候最最让我头疼的两种排序方法,选择排序法 和 冒泡排序法. ...