思维水题:UVa512-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.
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: EX r1 c1 r2 c2
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; A is 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 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)
解题心得:
- 题意就是给你一个表,然后进行行列的删除、增加空白的行列、两个个表格的交换操作,然后询问原本表中的位置的值在进行一系列操作之后在表中的位置(或者不存在)。
- 这个题思维难度不是很大,但是它要折磨你,很恼火,稍不注意就会写bug,做的方法有很多,我这里用的是简单的模拟。要注意一点就是这个题目上面给的例子并不是样例,只是给你解释一下大概的意思,被坑。
- 如果就模拟,可以建立两个表,一个初始表,一个变化后的表,然后直接对照这两个表就行了,但是在模拟的过程中要注意,每次插入或者删除操作是同时进行的(就是不能在前面的删除操作过程中对下面要进行的行列的操作产生影响),所有在插入或者删除的时候要先从从数值大的行列进行操作,不然先改变前面的行或者列会影响后面的行和列。
- 然后就是输出问题要注意其中一句话,将每两个例子用空白行分离,但最后一个例子后面不打印空行,不注意会PE。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 60;
int maps[2][maxn][maxn];//maps[0][n][m]表示原表,maps[1][n][m]表示改变后表
int op[maxn];
int n,m,q,n1,m1;
char s[maxn];
void EX()
{
int r1,c1,c2,r2;
scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
swap(maps[1][r1][c1],maps[1][r2][c2]);
}
void pre_maps()
{
int t = 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
maps[0][i][j] = maps[1][i][j] = t++;
}
void DR()
{
int times;
scanf("%d",×);
for(int i=0;i<times;i++)
scanf("%d",&op[i]);
sort(op,op+times);//先对后面的行列进行操作以免产生影响,后面的后面
for(int i=times-1;i>=0;i--)
{
int r = op[i];
for(int i=r;i<=n1;i++)
for(int j=1;j<=m1;j++)
maps[1][i][j] = maps[1][i+1][j];
}
n1-=times;//记录剩下的行列
}
void DC()
{
int times;
scanf("%d",×);
for(int i=0;i<times;i++)
scanf("%d",&op[i]);
sort(op,op+times);
for(int i=times-1;i>=0;i--)
{
int c = op[i];
for(int i=c;i<=m1;i++)
for(int j=1;j<=n1;j++)
maps[1][j][i] = maps[1][j][i+1];
}
m1-=times;
}
void IR()
{
int times;
scanf("%d",×);
for(int i=0;i<times;i++)
scanf("%d",&op[i]);
sort(op,op+times);
for(int i=times-1;i>=0;i--)
{
int r = op[i];
for(int i=n1+1;i>r;i--)
for(int j=1;j<=m1;j++)
maps[1][i][j] = maps[1][i-1][j];
for(int j=1;j<=m1;j++)
maps[1][r][j] = 0;
n1++;
}
}
void IC()
{
int times;
scanf("%d",×);
for(int i=0;i<times;i++)
scanf("%d",&op[i]);
sort(op,op+times);
for(int i=times-1;i>=0;i--)
{
int c = op[i];
for(int i=m1+1;i>c;i--)
for(int j=1;j<=n1;j++)
maps[1][j][i] = maps[1][j][i-1];
for(int i=1;i<=n1;i++)
maps[1][i][c] = 0;
m1++;
}
}
void _find(int r,int c)
{
int va = maps[0][r][c];
for(int i=1;i<=n1;i++)
for(int j=1;j<=m1;j++)
{
if(maps[1][i][j] == va)
{
printf("Cell data in (%d,%d) moved to (%d,%d)\n",r,c,i,j);
return;
}
}
printf("Cell data in (%d,%d) GONE\n",r,c);
}
int main()
{
int Case = 1;
bool flag = false;
while(scanf("%d%d",&n,&m))
{
if(n + m == 0)
break;
if(flag)
printf("\n");//用来输出空行
flag = true;
n1 = n,m1 = m;
memset(maps,0,sizeof(maps));
pre_maps();
int opr;
scanf("%d",&opr);
while(opr--)
{
scanf("%s",s);
if(s[0] == 'E')
EX();
else if(s[0] == 'D' && s[1] == 'R')
DR();
else if(s[0] == 'D' && s[1] == 'C')
DC();
else if(s[0] == 'I' && s[1] == 'R')
IR();
else if(s[0] == 'I' && s[1] == 'C')
IC();
}
int query;
scanf("%d",&query);
printf("Spreadsheet #%d\n",Case++);
while(query--)
{
int r,c;
scanf("%d%d",&r,&c);
_find(r,c);
}
}
return 0;
}
思维水题:UVa512-Spreadsheet Tracking的更多相关文章
- HDU 2674 N!Again(数学思维水题)
题目 //行开始看被吓一跳,那么大,没有头绪, //看了解题报告,发现这是一道大大大的水题,,,,,//2009 = 7 * 7 * 41//对2009分解,看它有哪些质因子,它最大的质因子是41,那 ...
- HDOJ/HDU 1256 画8(绞下思维~水题)
Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...
- 2019年华南理工校赛(春季赛)--I--炒股(简单思维水题)
水题,想想就过了 题目如下: 链接:https://ac.nowcoder.com/acm/contest/625/I来源:牛客网 攒机一时爽,一直攒机一直爽. 沉迷攒机的胡老师很快就发现,他每天只能 ...
- Iroha and a Grid AtCoder - 1974(思维水题)
就是一个组合数水题 偷个图 去掉阴影部分 把整个图看成上下两个矩形 对于上面的矩形求出起点到每个绿点的方案 对于下面的矩形 求出每个绿点到终点的方案 上下两个绿点的方案相乘后相加 就是了 想想为什么 ...
- 【CodeForces - 707B】Bakery(思维水题)
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...
- CodeForces 604C 【思维水题】`
题意: 给你01字符串的长度再给你一个串. 然后你可以在这个串中选择一个起点和一个终点使得这个连续区间内所有的位取反. 求: 经过处理后最多会得到多少次01变换. 例如:0101是4次,0001是2次 ...
- 又一道简单题&&Ladygod(两道思维水题)
Ladygod Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- 【Gym - 100923A】Por Costel and Azerah(思维水题)
Por Costel and Azerah Descriptions 给你n个数 问你,有多少个子序列 的和是偶数 Example Input 233 10 124 2 Output 33 题目链接 ...
- codeforces 804A Find Amir 思维/水题
A few years ago Sajjad left his school and register to another one due to security reasons. Now he w ...
随机推荐
- Spark Mllib里的向量标签概念、构成(图文详解)
不多说,直接上干货! Labeled point: 向量标签 向量标签用于对Spark Mllib中机器学习算法的不同值做标记. 例如分类问题中,可以将不同的数据集分成若干份,以整数0.1.2,... ...
- android模拟器创建时的PANIC: Could not open:错误的解决
创建AVD之后,在启动时报如下错误,解决方法如下: 在环境变量中创建ANDROID_SDK_HOME=D:\Program Files (x86)\Android\android-sdk,后面的当然是 ...
- 01SpringBase
Spring (容器) 概述: 01.Java EE开发者的春天 02.主要目的是 降低业务逻辑层和其他层的耦合度 IOC 03.spring容器是用来创建(new)和管理(对象之间的关系)程序中所有 ...
- 多线程串口通信 MFC CSerialPort
写在前面: 晚上应该继续完成未写完的代码,但Chrome上打开的标签实在太多了,约30个了,必须关掉一些,所以需要把自己看的整理一下然后关掉.本次主要写点MFC环境下多线程串口通信相关的东西,这包括线 ...
- 用户登录保存数据实例(慕课笔记 使用SharedPreferences保存用户名)
学习视频之后自己操作时的笔记. 0.视频地址:http://www.imooc.com/video/3265 1.功能预览: 说明:1)输入错误用户名和密码,点击登录,弹出提示框“禁止登录”: 2)输 ...
- python中的getcwd
Help on built-in function getcwd in module posix: getcwd(...) getcwd() -> path Return a ...
- java面试题(杨晓峰)---以面试题为切入点,有效提升你的java内功
java是一门历史悠久的编程语言,可以毫无争议的说,java是最主流的编程语言之一.全球有1200万以上的java程序猿以及海量的设备,还有无所不能的java生态圈. 我所知道的诸如阿里,京东,百度, ...
- 2017-3-7-lint82single-number
2017-3-7-lint82single-number 在河之洲 算法 小书匠 problem 82single-number/ solution int singleNumber(vector&l ...
- PHP生成类似类似优酷、腾讯视频等其他视频链的ID
不知道你注意了没有,类似优酷.腾讯视频等其他视频链接似乎类似这样的 http://v.youku.com/v_show/id_XNjA5MjE5OTM2.html 注意id_xxx那段,是不是看不懂了 ...
- UVA 1615 Highway 高速公路 (区间选点)
题意:在一条线段上选出尽量少的点,使得和所有给出的n个点距离不超过D. 分别计算出每个点在线段的满足条件的区间,然后就转化成了区间选点的问题了,按照右端点排序,相同时按照左端点排序,按照之前的排序一定 ...