【例题 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;
}
原文地址:https://www.cnblogs.com/AWCXV/p/9837288.html