【例题 4-5 uva 512】Spreadsheet Tracking
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
每个操作对与一个点来说变化是固定的。
因此可以不用对整个数组进行操作。
对于每个询问,遍历所有的操作。对输入的(x,y)进行相应的变换就好了。
数据之间有空行。
【代码】
/*
ope=0 EX操作 交换a[x1][y1],a[x2][y2]
ope=1 DR操作 删除v中的行(无序)
ope=2 IR操作 在v中的位置插入空行(无顺序)
ope=3 DC操作 删除v中的列(无序)
ope=4 IC操作 插入v中的列(无序)
*/
#include <bits/stdc++.h>
using namespace std;
int r,c;
int n;
struct abc{
int ope;
vector<int> v;
};
abc temp;
vector<abc> a;
void input_mul(int ope){
temp.ope = ope;
temp.v.clear();
int cnt;cin >> cnt;
for (int j = 0;j < cnt;j++){
int x;
cin >> x;
temp.v.push_back(x);
}
a.push_back(temp);
}
int main()
{
//freopen("/home/ccy/rush.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0);
int kase = 0;
while (cin >> r >> c){
if (r==0 && c==0) break;
if (kase>0) cout<<endl;
cout<<"Spreadsheet #"<<++kase<<endl;
a.clear();
cin >> n;
for (int i = 0;i < n;i++){
string ts;
cin >> ts;
if (ts=="EX"){
temp.ope = 0;
temp.v.resize(4);
for (int j = 0;j < 4;j++) cin >> temp.v[j];
a.push_back(temp);
}
if (ts=="DR") input_mul(1);
if (ts=="IR") input_mul(2);
if (ts=="DC") input_mul(3);
if (ts=="IC") input_mul(4);
}
int q;
cin >> q;
while (q--){
int x,y,tx,ty;
cin >> x >> y;
tx = x,ty = y;
bool ok = 1;
for (int i = 0;i < (int) a.size();i++){
if (a[i].ope==0){
int x1,y1,x2,y2;
x1 = a[i].v[0],y1 = a[i].v[1];
x2 = a[i].v[2],y2 = a[i].v[3];
if (x1==x && y1 == y){
x = x2;y = y2;
}else
if (x2==x && y2==y){
x = x1;y = y1;
}
}
if (a[i].ope==1){
int subx = 0;
for (int rr:a[i].v){
if (rr<x) subx++;else if (rr==x) ok = 0;
}
x-=subx;
}
if (a[i].ope==2){
int addx = 0;
for (int rr:a[i].v){
if (rr<=x) addx++;
}
x+=addx;
}
if (a[i].ope==3){
int suby = 0;
for (int cc:a[i].v){
if (cc<y) suby++;else if (cc==y) ok = 0;
}
y-=suby;
}
if (a[i].ope==4){
int addy = 0;
for (int cc:a[i].v){
if (cc<=y) addy++;
}
y+=addy;
}
}
cout<<"Cell data in ("<<tx<<","<<ty<<") ";
if (ok==0){
cout<<"GONE"<<endl;
}else{
cout<<"moved to ("<<x<<","<<y<<")"<<endl;
}
}
}
return 0;
}
【例题 4-5 uva 512】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
Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and ...
- uva 512
1. 问题 不知道怎么存储操作 看代码注释,else if等 2. 代码 #include <iostream> #include <stdio.h> #include < ...
- 踪电子表格中的单元格(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) 所示 ...
- UVA 215 Spreadsheet Calculator (模拟)
模拟题.每个单元格有表达式就dfs,如果有环那么就不能解析,可能会重复访问到不能解析的单元格,丢set里或者数组判下重复. 这种题首先框架要对,变量名不要取的太乱,细节比较多,知道的库函数越多越容易写 ...
- 思维水题:UVa512-Spreadsheet Tracking
Spreadsheet Tracking Data in spreadsheets are stored in cells, which are organized in rows (r) and c ...
- D5 LCA 最近公共祖先
第一题: POJ 1330 Nearest Common Ancestors POJ 1330 这个题可不是以1为根节点,不看题就会一直wa呀: 加一个找根节点的措施: #include<alg ...
- 算法笔记--斜率优化dp
斜率优化是单调队列优化的推广 用单调队列维护递增的斜率 参考:https://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html 以例1举 ...
- 回文树&后缀自动机&后缀数组
KMP,扩展KMP和Manacher就不写了,感觉没多大意思. 之前感觉后缀自动机简直可以解决一切,所以不怎么写后缀数组. 马拉车主要是通过对称中心解决问题,有的时候要通过回文串的边界解决问题 ...
随机推荐
- 3.CCFadeOutTRTiles,部落格效果,跳动的方块特效,3D瓷砖晃动特效,破碎的3D瓷砖特效,瓷砖洗牌特效,分多行消失特效,分多列消失特效
1 TiledGrid3D //TiledGrid3D //CCFadeOutTRTiles * action = CCFadeOutTRTiles::create(2, CCSize(20,2 ...
- B1232 [Usaco2008Nov]安慰奶牛cheer 最小生成树
%%%小詹太巨啦!!!我就想直接最小生成树之后建树跑dfs,然后写跪了...然后看小詹博客之后恍然大悟,原来直接把边权改为w * 2 + 两边点权值就行了. 但是还是不对,为什么呢?原来我们起点走了三 ...
- bzoj 3209 花神的数论题 —— 数位DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3209 算是挺简单的数位DP吧,但还是花了好久才弄明白... 又参考了博客:https://b ...
- 树莓派(raspberry)启用root账户
树莓派使用的linux是debian系统,所以树莓派启用root和debian是相同的. debian里root账户默认没有密码,但账户锁定. 当需要root权限时,由默认账户经由sudo执行,Ras ...
- Django day06 模版层(二) 过滤器 标签
一: 模板语言之过滤器: " | " 前后的区分: 前面的是函数的第一个参数, 后面的是python的一个函数, 冒号后面的是第二个参数例: <p>过滤器之默认值:{ ...
- input点击修改样式
<input id="geren" type="button" value="个人奖励" style="BORDER-TOP ...
- C# 获取当月有多少天
int days = DateTime.DaysInMonth ( 2009, 9 ); int days = DateTime.DaysInMonth ( DateTime.Now.Year, Da ...
- thymeleaf公共页面元素抽取
1.抽取公共片段 使用thymeleaf的th:fragment为样抽取的公共片段命名, 如下把div标签命名为 copy,就可以获取到div整个里的内容<div th:fragment=&qu ...
- gitlab克隆报错:remote: HTTP Basic: Access denied;remote: You must use a personal access token with ‘api’ scope for Git over HTTP.
错误: remote: HTTP Basic: Access denied remote: You must use a personal access token with ‘api’ scope ...
- 最小生成树之Prim算法(最原始最详细入门)
//算法6.8 普里姆算法 #include <iostream> using namespace std; typedef char VerTexType; typedef int Ar ...