ACM 粗心永远AC不了系列——UVA 512
来源:互联网 发布:乐宝宝 乐普数据下载 编辑:程序博客网 时间:2024/05/30 04:35
此题在算法竞赛入门经典第二版中85页有详解,我先自己想了一下思路,然后看书上的思路,发现书上第二中方法的思路非常的巧妙,在不看代码的情况下自己实现了,特此标记。
题目详细在最下方,这里先总结我的一点小小的心得。
此题模拟Excel的变换,最首先想到的思路是用一个二维数组来模拟该操作,只不过这样子会使整个算法效率很地底下,但是较为容易想到。
另一种思路,变换类型的题,但凡他是要求结果不论过程的,我们完全可以不用按过程全部实现,在此题,只需要实现他要查看的数的变换即可。这里的思路是每一次变换后,要查每一个数,每次只需要对每一个数进行变换即可,不用存储下中间结果。这样子针对若干大个数的变换操作就会变成对一个数的变换操作,感觉一下容易了很多。
UVA 512 - Spreadsheet Tracking
Data in spreadsheets are stored in cells, which are organized in rows (r) and columns (c). Some
operations on spreadsheets can be applied to single cells (r; c), while others can be applied to entire
rows or columns. Typical cell operations include inserting and deleting rows or columns and exchanging
cell contents.
Some spreadsheets allow users to mark collections of rows or columns for deletion, so the entire
collection can be deleted at once. Some (unusual) spreadsheets allow users to mark collections of rows
or columns for insertions too. Issuing an insertion command results in new rows or columns being
inserted before each of the marked rows or columns. Suppose, for example, the user marks rows 1 and
5 of the spreadsheet on the left for deletion. The spreadsheet then shrinks to the one on the right.
2 24 6 8 22 12 14 16 1818 19 20 21 22 23 24 25 2624 25 26 67 22 69 70 71 7716 12 11 10 22 56 57 58 5933 34 35 36 22 38 39 40 41
If the user subsequently marks columns 3, 6, 7, and 9 for deletion, the spreadsheet shrinks to this.
2 24 8 22 1618 19 21 22 2524 25 67 22 7116 12 10 22 5833 34 36 22 40
If the user marks rows 2, 3 and 5 for insertion, the spreadsheet grows to the one on the left. If the
user then marks column 3 for insertion, the spreadsheet grows to the one in the middle. Finally, if the
user exchanges the contents of cell (1,2) and cell (6,5), the spreadsheet looks like the one on the right.
2 24 8 22 1618 19 21 22 2524 25 67 22 7116 12 10 22 5833 34 36 22 40
2 24 8 22 1618 19 21 22 2524 25 67 22 7116 12 10 22 5833 34 36 22 40
2 22 8 22 1618 19 21 22 2524 25 67 22 7116 12 10 24 5833 34 36 22 40
You must write tracking software that determines the final location of data in spreadsheets that
result from row, column, and exchange operations similar to the ones illustrated here.
Input
The input consists of a sequence of spreadsheets, operations on those spreadsheets, and queries about
them. Each spreadsheet definition begins with a pair of integers specifying its initial number of rows
(r) and columns (c), followed by an integer specifying the number (n) of spreadsheet operations. Row
and column labeling begins with 1. The maximum number of rows or columns of each spreadsheet is
limited to 50. The following n lines specify the desired operations.
An operation to exchange the contents of cell (r1; c1) with the contents of cell (r2; c2) is given by:
EX r1c1 r2c2
The four insert and delete commands|DC(delete columns), DR(delete rows), IC(insert columns),
and IR (insert rows) are given by:
< command > A x1 x2 : : : xA
where < command >is one of the four commands; Ais a positive integer less than 10, and x1; : : : ; xA
are the labels of the columns or rows to be deleted or inserted before. For each insert and delete
command, the order of the rows or columns in the command has no significance. Within a single delete
or insert command, labels will be unique.
The operations are followed by an integer which is the number of queries for the spreadsheet. Each
query consists of positive integers r andc, representing the row and column number of a cell in the
original spreadsheet. For each query, your program must determine the current location of the data
that was originally in cell (r; c). The end of input is indicated by a row consisting of a pair of zeros for
the spreadsheet dimensions.
Output
For each spreadsheet, your program must output its sequence number (starting at 1). For each query,
your program must output the original cell location followed by the final location of the data or the
word ‘GONE’ if the contents of the original cell location were destroyed as a result of the operations.
Separate output from different spreadsheets with a blank line.
The data file will not contain a sequence of commands that will cause the spreadsheet to exceed the
maximum size.
Sample Input
7 9
5
DR 2 1 5
DC 4 3 6 7 9
IC 1 3
IR 2 2 4
EX 1 2 6 5
4
4 8
5 5
7 8
6 5
0 0
Sample Output
Spreadsheet #1
Cell data in (4,8) moved to (4,6)
Cell data in (5,5) GONE
Cell data in (7,8) moved to (7,6)
Cell data in (6,5) moved to (1,2)
- ACM 粗心永远AC不了系列——UVA 512
- ACM 粗心永远AC不了系列——UVa 213 Message Decoding(World Finals1991,字符串) |二维数组的妙用
- ACM 粗心永远AC不了系列——HDU 1097 A hard puzzle
- ACM 粗心永远AC不了系列——小Hi的烦恼|“五维数点”问题
- ACM 粗心永远AC不了系列——HDU 1754 I Hate It|线段树区间求最值
- ACM 粗心永远AC不了系列——Demo Day|三维DP问题,机器人寻路,hiho一下第150周
- HDU ACM 4511 小明系列故事——女友的考验->AC自动机+DP
- ACM常用模板——ac自动机
- CSDN日报20170423 ——《私活,永远解救不了自己屌丝的人生!》
- 失败的代名词——粗心
- ACM-贪心之今年暑假不AC——hdu2037
- ACM杭电的AC回顾——2025
- ACM杭电的AC回顾——2026
- ACM杭电的AC回顾——2027
- ACM杭电的AC回顾——2028
- ACM杭电的AC回顾——2029
- UVA 11468 —— Substring(AC自动机+DP)
- AC自动机 ( 静态建树模板 )——Substring ( UVA 11468 )
- 最新的苹果证书申请流程
- boneCP的连接管理
- 程序员必读书单
- iOS开发之Notification与多线程
- Memcache运行状况
- ACM 粗心永远AC不了系列——UVA 512
- 23种设计模式之_命令行模式
- Android命令行/c语言/java设置获取系统属性(getprop/setprop)的方法
- 配置dubbo-admin的管理页面
- [C++]类成员冒号初始化以及构造函数内赋值
- Android自定义圆角Dialog
- jQuery EasyUI详解-EasyUI表单 文本框 按钮
- 计算机领域经典巨著TAOCP卷3上市!【含赠书】
- C 语言--sizeof与typedef