Spreadsheet Tracking
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的更多相关文章
- Uva - 512 - Spreadsheet Tracking
Data in spreadsheets are stored in cells, which are organized in rows (r) and columns (c). Some oper ...
- 踪电子表格中的单元格(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) 所示 ...
- 【例题 4-5 uva 512】Spreadsheet Tracking
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个操作对与一个点来说变化是固定的. 因此可以不用对整个数组进行操作. 对于每个询问,遍历所有的操作.对输入的(x,y)进行相应的变 ...
- 思维水题:UVa512-Spreadsheet Tracking
Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...
- Metaio在Unity3D中报错 Start: failed to load tracking configuration: TrackingConfigGenerated.xml 解决方法
报错:Start: failed to load tracking configuration: TrackingConfigGenerated.xml Start: failed to load t ...
- SharePoint 2010 Survey的Export to Spreadsheet功能怎么不见了?
背景信息: 最近用户报了一个问题,说他创建的Survey里将结果导出成Excel文件(Export to spreadsheet)的按钮不见了. 原因排查: 正常情况下,这个功能只存在于SharePo ...
- SQL Server 更改跟踪(Chang Tracking)监控表数据
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 主要区别与对比(Compare) 实现监控表数据步骤(Process) 参考文献(Refere ...
- 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 ...
- undefined reference to `Spreadsheet::staticMetaObject'
<C++ GUI Qt 4 编程>学习 一.遇到的问题 在学完第4章后,Spreasheet程序也已经写好了.在用 FindDialog 搜索时发现没有效果. 二.解决过程 调试跟踪代码, ...
随机推荐
- Vim小知识
在退出vim编辑的时候,强制退出是q! 感叹号在前,即!q,表示执行外部shell命令,感叹号在后,即q!,表示强制执行vi命令.
- 自学hadoop(三)
1) 关于hadoop在eclipse插件.经过自己的摸爬滚打.总结一下三条. a) 2.0或者0.23.0吧 google比较方便.其他的可以自己编译.(这个我不敢保证.我本地环境事2.1. ...
- Ubuntu_wifi&pppoe
学校现在上网全部要拨号,加上我在宿舍用的是无线路由,也就是要在ubuntu下实现连接wifi后再拨号,这个功能在默认的ubuntu网络设置里面是没有的,里面有dsl但是对有线网络使用的,有点小郁闷.不 ...
- SQL游标遍历数据表
DECLARE @资产编号 VARCHAR(50) ,@gsid VARCHAR(50) DECLARE test_Cursor CURSOR LOCAL FOR SELECT 资产编号,gsid F ...
- windows下安装和配置Weka
Weka是一款免费的,非商业化的,基于java环境下的开源的机器学习以及数据挖掘软件.Weka里含有各种数据挖掘工具:数据预处理,分类与回归,聚类,关联规则和可视化工具. 一.安装weka 我们首先需 ...
- work4
任务概述 给出多条英文单词,找出一个包含所有单词的填字阵.并且对于该方阵有一定特殊要求: a) Stage 1 Every phrase in the input file is cover ...
- Delphi实例-IdTCPServer和IdTCPClient的使用(支持文件发送)
相关资料: http://blog.csdn.net/earbao/article/details/46514313 结果注意: 1.Use IdContext.IdGlobal 这两个单元2.不能使 ...
- HDU 4370 0 or 1 (最短路+最小环)
0 or 1 题目链接: Rhttp://acm.hust.edu.cn/vjudge/contest/122685#problem/R Description Given a n*n matrix ...
- Unity3D之Mecanim动画系统学习笔记(六):使用脚本控制动画
控制人物动画播放 这里我重新弄了一个简单的场景和新的Animator Controller来作为示例. 下面先看看Animator Controller的配置: 人物在站立状态只能进入走路,走路只能进 ...
- [置顶] 文件和目录(一)--unix环境高级编程
普通文件和目录linux中最多的两类文件,linux中一共有七种类型的文件,如下: 1.普通文件 2.目录 3.字符特殊设备 4.块特殊设备 5.FIFO,又叫命名管道 6.Socket,即套接字 7 ...