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.

If the user subsequently marks columns 3, 6, 7, and 9 for deletion, the spreadsheet shrinks to this.

1 2 3 4 5
1 2 24 8 22 16
2 18 19 21 22 25
3 24 25 67 22 71
4 16 12 10 22 58
5 33 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.

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:

EXr1c1r2c2

The four insert and delete commands--DC (delete columns), DR (delete rows), IC (insert columns), and IR (insert rows) are given by:

<command> Ax1x2xA

where <command> is one of the four commands; A is a positive integer less than 10, and
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 and c,
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)
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const double EXP=1e-;
const double PI=acos(-1.0);
const int INF=0x7fffffff;
const int MS=;
const int MAX=; struct command
{
char c[];
int r1,c1,r2,c2;
int n;
int x[MS];
}cmd[MAX];
int R,C,N,Q;
int find(int &r0,int &c0)
{
for(int i=;i<N;i++)
{
if(cmd[i].c[]=='E')
{
if(cmd[i].r1==r0&&cmd[i].c1==c0)
{
r0=cmd[i].r2;
c0=cmd[i].c2;
}
else if(cmd[i].r2==r0&&cmd[i].c2==c0)
{
r0=cmd[i].r1;
c0=cmd[i].c1;
}
}
else
{
int dr=,dc=;
for(int j=;j<cmd[i].n;j++)
{
int x=cmd[i].x[j];
if(cmd[i].c[]=='I')
{
if(cmd[i].c[]=='R'&&x<=r0)
dr++;
if(cmd[i].c[]=='C'&&x<=c0)
dc++;
}
else
{
if(cmd[i].c[]=='R'&&x==r0)
return ;
if(cmd[i].c[]=='C'&&x==c0)
return ;
if(cmd[i].c[]=='R'&&x<r0)
dr--;
if(cmd[i].c[]=='C'&&x<c0)
dc--;
}
}
r0+=dr;
c0+=dc;
}
}
return ;
}
int main()
{
int r0,c0,kase=;
while(scanf("%d%d%d",&R,&C,&N)==&&R)
{
for(int i=;i<N;i++)
{
scanf("%s",cmd[i].c);
if(cmd[i].c[]=='E')
scanf("%d%d%d%d",&cmd[i].r1,&cmd[i].c1,&cmd[i].r2,&cmd[i].c2);
else
{
scanf("%d",&cmd[i].n);
for(int j=;j<cmd[i].n;j++)
scanf("%d",&cmd[i].x[j]);
}
}
if(kase>)
printf("\n");
printf("Spreadsheet #%d\n",++kase);
scanf("%d",&Q);
while(Q--)
{
scanf("%d%d",&r0,&c0);
printf("Cell data in (%d,%d) ",r0,c0);
if(!find(r0,c0))
printf("GONE\n");
else
printf("moved to (%d,%d)\n",r0,c0);
}
}
return ;
}

Spreadsheet Tracking的更多相关文章

  1. Uva - 512 - Spreadsheet Tracking

    Data in spreadsheets are stored in cells, which are organized in rows (r) and columns (c). Some oper ...

  2. 踪电子表格中的单元格(Spreadsheet Tracking, ACM/ICPC World Finals 1997, UVa512)

    有一个r行c列(1≤r,c≤50)的电子表格,行从上到下编号为1-r,列从左到右编号为1 -c.如图4-2(a)所示,如果先删除第1.5行,然后删除第3, 6, 7, 9列,结果如图4-2(b) 所示 ...

  3. 【例题 4-5 uva 512】Spreadsheet Tracking

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个操作对与一个点来说变化是固定的. 因此可以不用对整个数组进行操作. 对于每个询问,遍历所有的操作.对输入的(x,y)进行相应的变 ...

  4. 思维水题:UVa512-Spreadsheet Tracking

    Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...

  5. Metaio在Unity3D中报错 Start: failed to load tracking configuration: TrackingConfigGenerated.xml 解决方法

    报错:Start: failed to load tracking configuration: TrackingConfigGenerated.xml Start: failed to load t ...

  6. SharePoint 2010 Survey的Export to Spreadsheet功能怎么不见了?

    背景信息: 最近用户报了一个问题,说他创建的Survey里将结果导出成Excel文件(Export to spreadsheet)的按钮不见了. 原因排查: 正常情况下,这个功能只存在于SharePo ...

  7. SQL Server 更改跟踪(Chang Tracking)监控表数据

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 主要区别与对比(Compare) 实现监控表数据步骤(Process) 参考文献(Refere ...

  8. Computer Vision: OpenCV, Feature Tracking, and Beyond--From <<Make Things See>> by Greg

    In the 1960s, the legendary Stanford artificial intelligence pioneer, John McCarthy, famously gave a ...

  9. undefined reference to `Spreadsheet::staticMetaObject'

    <C++ GUI Qt 4 编程>学习 一.遇到的问题 在学完第4章后,Spreasheet程序也已经写好了.在用 FindDialog 搜索时发现没有效果. 二.解决过程 调试跟踪代码, ...

随机推荐

  1. codeforce 702D Road to Post Office 物理计算路程题

    http://codeforces.com/contest/702 题意:人到邮局去,距离d,汽车在出故障前能跑k,汽车1公里耗时a,人每公里耗时b,修理汽车时间t,问到达终点最短时间 思路:计算车和 ...

  2. HDU5727 Necklace

    http://acm.hdu.edu.cn/showproblem.php?pid=5727 题意:n个珠子,每个珠子有阴阳两种属性,且阴的一定和阳的紧邻,排成一个环:m行,每行两个数,表示阳性x珠子 ...

  3. OpenJDK与JDK的区别及Ubuntu下的安装方法

    OpenJDK与JDK的区别: OpenJDK是JDK的开放原始码版本,以GPL协议的形式放出.两者的授权协议的不同,且在采用GPL协议的OpenJDK中,SUNJDK的一部分源代码因为产权的问题无法 ...

  4. HDU 5833 Zhu and 772002 (高斯消元)

    Zhu and 772002 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5833 Description Zhu and 772002 are b ...

  5. iOS 使用FMDB SQLCipher给数据库加密

    关于SQLite,SQLCipher和FMDB SQLite是一个轻量的.跨平台的.开源的数据库引擎,它的在读写效率.消耗总量.延迟时间和整体简单性上具有的优越性,使其成为移动平台数据库的最佳解决方案 ...

  6. 应用JConsole学习Java GC

    应用JConsole学习Java GC 关于Java GC的知识,好多地方都讲了很多,今天我用JConsole来学习一下Java GC的原理. GC原理 在我的上一篇中介绍了Java运行时数据区,在了 ...

  7. poj 3268 Silver Cow Party(最短路)

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17017   Accepted: 7767 ...

  8. [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储

    A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改)   这个代码 ...

  9. UVaLive 6859 Points (几何,凸包)

    题意:给定 n 个点,让你用最长的周长把它们严格包围起来,边长只能用小格子边长或者是小格子对角线. 析:先把每个点的上下左右都放到一个集合中,然后求出一个凸包,然后先边长转成题目的方式,也好转两个点的 ...

  10. Javascript高级篇-JS闭包

    Javascript闭包 1.变量的作用域 1.1局部变量 1.2全局变量(声明在外边或不用var来声明的变量) 2.外部读取方法内部的局部(私有)变量 function a(){ var b = & ...