依照题意模拟即可
uva上显式测试数据有一个没过,但程序依旧AC
#include<iostream> #include<cmath> #include<cstdio> #include<cstdlib> #include<cstring> #include<iomanip> #include<assert.h> #include<ctime> #include<vector> #include<list> #include<map> #include<set> #include<sstream> #include<stack> #include<queue> #include<string> #include<bitset> #include<algorithm> using namespace std; #define me(s) memset(s,0,sizeof(s)) #define pf printf #define sf scanf #define Di(x) int x;scanf("%d",&x) #define in(x) inp(x) #define in2(x,y) inp(x),inp(y) #define in3(x,y,z) inp(x),inp(y),inp(z) #define ins(x) scanf("%s",x) #define ind(x) scanf("%lf",&x) #define IO ios_base::sync_with_stdio(0);cin.tie(0) #define READ freopen("C:/Users/ASUS/Desktop/in.txt","r",stdin) #define WRITE freopen("C:/Users/ASUS/Desktop/out.txt","w",stdout) template<class T> void inp(T &x) {//读入优化 char c = getchar(); x = 0; for (; (c < 48 || c>57); c = getchar()); for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; } } typedef pair <int, int> pii; typedef long long ll; typedef unsigned long long ull; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const double pi = acos(-1.0); const double eps = 1e-15; const int maxn=50+5; const int Hash=maxn*maxn; int d[maxn][maxn],d2[maxn][maxn],ans[maxn][maxn],cols[maxn]; int r,c,n; void init(){ //READ; //WRITE; } void copy(char type,int p,int q){ if(type=='R'){ for(int i=1;i<=c;i++) d[p][i]=d2[q][i]; }else { for(int i=1;i<=r;i++) d[i][p]=d2[i][q]; } } void del(char type){ memcpy(d2,d,sizeof(d)); int cnt=type=='R'?r:c; int k=0; for(int i=1;i<=cnt;i++){ if(!cols[i]) copy(type,++k,i); } if(type=='R') r=k; else c=k; } void Ins(char type){ memcpy(d2,d,sizeof(d)); int cnt=type=='R'?r:c; int k=0; for(int i=1;i<=cnt;i++){ if(cols[i]) copy(type,++k,0); copy(type,++k,i); } if(type=='R') r=k; else c=k; } int main(){ init(); me(d); int cas=0,r1,c1,r2,c2,q; char cmd[10]; while(sf("%d%d%d",&r,&c,&n)==3){ for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) d[i][j]=(i*Hash)+j; for(int i=0;i<n;i++){ ins(cmd); if(cmd[0]=='E'){ in2(r1,c1);in2(r2,c2); int tmp=d[r1][c1]; d[r1][c1]=d[r2][c2];d[r2][c2]=tmp; }else { int a;in(a); me(cols); for(int i=0;i<a;i++) {Di(x);cols[x]=1;} if(cmd[0]=='D') del(cmd[1]); else Ins(cmd[1]); } } me(ans); for(int i=1;i<=r;i++) for(int j=1;j<=c;j++){ int tmp=d[i][j]; ans[tmp/Hash][tmp%Hash]=i*100+j; } in(q); if(cas) puts(""); pf("Spreadsheet #%d\n",++cas); while(q--){ in2(r1,c1); pf("Cell data in (%d,%d) ",r1,c1); if(!ans[r1][c1]) pf("GONE\n"); else pf("moved to (%d,%d)\n",ans[r1][c1]/100,ans[r1][c1]%100); } } }