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)
  1 #include <iostream>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <algorithm>
  5 #include <cmath>
  6 #include <map>
  7 #include <set>
  8 #include <stack>
  9 #include <queue>
 10 #include <string>
 11 #include <vector>
 12 using namespace std;
 13 const double EXP=1e-8;
 14 const double PI=acos(-1.0);
 15 const int INF=0x7fffffff;
 16 const int MS=55;
 17 const int MAX=10005;
 18
 19 struct command
 20 {
 21     char c[5];
 22     int r1,c1,r2,c2;
 23     int n;
 24     int x[MS];
 25 }cmd[MAX];
 26 int R,C,N,Q;
 27 int find(int &r0,int &c0)
 28 {
 29     for(int i=0;i<N;i++)
 30     {
 31         if(cmd[i].c[0]==‘E‘)
 32         {
 33             if(cmd[i].r1==r0&&cmd[i].c1==c0)
 34             {
 35                 r0=cmd[i].r2;
 36                 c0=cmd[i].c2;
 37             }
 38             else if(cmd[i].r2==r0&&cmd[i].c2==c0)
 39             {
 40                 r0=cmd[i].r1;
 41                 c0=cmd[i].c1;
 42             }
 43         }
 44         else
 45         {
 46             int dr=0,dc=0;
 47             for(int j=0;j<cmd[i].n;j++)
 48             {
 49                 int x=cmd[i].x[j];
 50                 if(cmd[i].c[0]==‘I‘)
 51                 {
 52                     if(cmd[i].c[1]==‘R‘&&x<=r0)
 53                         dr++;
 54                     if(cmd[i].c[1]==‘C‘&&x<=c0)
 55                         dc++;
 56                 }
 57                 else
 58                 {
 59                     if(cmd[i].c[1]==‘R‘&&x==r0)
 60                         return 0;
 61                     if(cmd[i].c[1]==‘C‘&&x==c0)
 62                         return 0;
 63                     if(cmd[i].c[1]==‘R‘&&x<r0)
 64                         dr--;
 65                     if(cmd[i].c[1]==‘C‘&&x<c0)
 66                         dc--;
 67                 }
 68             }
 69             r0+=dr;
 70             c0+=dc;
 71         }
 72     }
 73     return 1;
 74 }
 75 int main()
 76 {
 77     int r0,c0,kase=0;
 78     while(scanf("%d%d%d",&R,&C,&N)==3&&R)
 79     {
 80         for(int i=0;i<N;i++)
 81         {
 82             scanf("%s",cmd[i].c);
 83             if(cmd[i].c[0]==‘E‘)
 84                 scanf("%d%d%d%d",&cmd[i].r1,&cmd[i].c1,&cmd[i].r2,&cmd[i].c2);
 85             else
 86             {
 87                 scanf("%d",&cmd[i].n);
 88                 for(int j=0;j<cmd[i].n;j++)
 89                     scanf("%d",&cmd[i].x[j]);
 90             }
 91         }
 92         if(kase>0)
 93             printf("\n");
 94         printf("Spreadsheet #%d\n",++kase);
 95         scanf("%d",&Q);
 96         while(Q--)
 97         {
 98             scanf("%d%d",&r0,&c0);
 99             printf("Cell data in (%d,%d) ",r0,c0);
100             if(!find(r0,c0))
101                 printf("GONE\n");
102             else
103                 printf("moved to (%d,%d)\n",r0,c0);
104         }
105     }
106     return 0;
107 }
时间: 2024-10-05 11:50:39

Spreadsheet Tracking的相关文章

UVALive5198 UVA512 Spreadsheet Tracking

World Finals >> 1997 - San Jose 问题链接:UVALive5198 UVA512 Spreadsheet Tracking. 问题简述:这是一个电子表格操作的模拟题.先输入电子表格总的行和列的正整数r和c,满足r,c<=50,r和c均为0时,输入测试实例结束:然后输入命令数n,跟着是n条命令,包括: 1. EX r1 c1 r2 c2,其含义是两个单元交换,即<r1,c1>和<r2,c2>内容交换: 2. 插入和删除命令,共4条,分别

追踪电子表格中的单元格

  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 ce

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 cel

算法竞赛入门经典 第四章

[√ ] UVA1339 古老的密码 Ancient Cipher [√ ] UVA489 刽子手的游戏 Hangman Judge [√ ] UVA133 救济金发放 The Dole Queue [√ ] UVA213 信息解码 Message Decoding [√ ] UVA512 追踪电子表格中的单元格 Spreadsheet Tracking [√ ] UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

POJ1420 Spreadsheet(拓扑排序)注意的是超内存

Spreadsheet Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 617   Accepted: 290 Description In 1979, Dan Bricklin and Bob Frankston wrote VisiCalc, the first spreadsheet application. It became a huge success and, at that time, was the ki

Method Tracking

一.能做什么? 直观的看到某个时间段内哪个方法花了多少时间. 二.工作台介绍 非独占时间: 某函数占用的CPU时间,包含内部调用其它函数的CPU时间. 独占时间: 某函数占用CPU时间,但不含内部调用其它函数所占用的CPU时间. 三.如何操作 点击Start Method Tracking, 一段时间后再点击一次, trace文件被自动打开, 我们如何判断可能有问题的方法? 通过方法的调用次数和独占时间来查看,通常判断方法是: 如果方法调用次数不多,但每次调用却需要花费很长的时间的函数,可能会有

Google Tango Java SDK开发:Motion Tracking 运动追踪

Java API Motion Tracking Tutorial运动追踪教程 This page describes how the Java API handles motion tracking. 该页面描述了如何使用Java API处理运动追踪. Lifecycle 生命周期 The normal motion tracking system lifecycle consists of three states: TangoPoseData.POSE_INITIALIZING, Tang

手势跟踪论文学习:Realtime and Robust Hand Tracking from Depth(三)Cost Function

iker原创.转载请标明出处:http://blog.csdn.net/ikerpeng/article/details/39050619 Realtime and Robust Hand Tracking from Depth中的Cost Function 学习 首先,我们应该知道,输入的数据是什么:3D 点云数据. 3D点云给我的感觉应该是这种 输出的是:拟合好的手模型(48球体模型). 而这里的的3D 点云数据用p表示,每个球体用Sx 表示. Ci 第i个球体的中心:D表示深度图( 区分还

Codeforces Round #401 (Div. 2) C. Alyona and Spreadsheet

题目链接:C. Alyona and Spreadsheet 题意: 给你一个n*m的矩阵,现在有k个询问,每次给你一个l,r,问你在[l,r]这行中能否有一列数十非递减的顺序 题解: 用vector来保存矩阵. 对于每一行n*m dp一下最远能达到的范围,然后询问的时候就判断l,r是否在这个范围内. 1 #include<bits/stdc++.h> 2 #define pb push_back 3 #define rs m+1,r,rt<<1|1 4 #define mst(a