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> Ax1x2
xA
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 搜索时发现没有效果. 二.解决过程 调试跟踪代码, ...
随机推荐
- leetcode—Valid Parentheses
1.问题描述 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if t ...
- mysql performance_schema 初探
mysql performance_schema 初探: mysql 5.5 版本 新增了一个性能优化的引擎: PERFORMANCE_SCHEMA 这个功能默认是关闭的: 需要设置参数: perf ...
- java的math常用方法
鉴于java求整时欲生欲死,整理常用math如下: 1: java取整 a:floor向下取整 用法:Math.floor(num) Math.floor(1.9)//1 ...
- 现代程序设计 homework-08
现代程序设计 homework-08 第八次作业. 理解C++变量的作用域和生命周期 作用域就是一个变量可以被引用的范围,如:全局作用域.文件作用域.局部作用域:而生命周期就是这个变量可以被引用的时间 ...
- Windows 下整理内存工具推荐——cleanmem
---恢复内容开始--- cleanmem 是个不错的内存整理工具,www.xdown.com 下载有便携版提供下载. 软件有pro版和free版,一般情况下,free版够用了,没必要用pro版. p ...
- 什么是USBMini接口
USB的接口有四种.一种是大头,有A型和B型两种,其中A型最常见,就是我们用的最多的标准的USB接头:一种是小头的,也就是USB Mini,也有A型和B型两种,其中B型应用最多,主要应用于手机.MP4 ...
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 (递推)
题意:略. 析:首先是假设前n-2个已经放好了,那么放第 n 个时,先考虑一下第 n-1 放的是什么,那么有两种情况. 如果n-1放的是和第1个一样的,那么第 n 个就可以在n-2的基础上放2个,也就 ...
- C#下内存管理--垃圾收集
章节安排 内存管理简介 垃圾回收机制 性能问题 C#下非托管资源的处理 要强调的几点 References 内存管理简介 对于任何一种编程语言,内存管理都是不得不提很重要的一块内容,但可惜的是目前为止 ...
- C#学习笔记(十):反射
反射 放射是指在程序运行时动态的获取类的信息的机制,我们下面来看看C#中的反射. Type Type 为 System.Reflection 功能的根,也是访问元数据的主要方式. 使用 Type 的成 ...
- @Override must override a superclass method 问题解决
一.问题的由来 最近接手了了一个合作企业的项目,前期不是我司开发的,上周做了几天的技术对接,客户端界面由我负责对接,从svn检出之后,迫不及待的导入到了本地的myeclipse中,谁知立马就出现了那个 ...





