UVA - 512 Spreadsheet Tracking
阿新 • • 發佈:2018-12-04
Spreadsheet Tracking
紫書第二個思路十分巧妙,能用很少的程式碼解出此題。
AC程式碼:
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #include <sstream> #include <iomanip> using namespace std; typedef long long ll; typedef unsigned long long ull; #define inf 0x3f3f3f3f #define rep(i,l,r) for(int i=l;i<=r;i++) #define lep(i,l,r) for(int i=l;i>=r;i--) #define ms(arr) memset(arr,0,sizeof(arr)) //priority_queue<int,vector<int> ,greater<int> >q; const int maxn = (int)1e5 + 5; const ll mod = 1e9+7; int t1; struct node { string idx; int n; int arr[15]; }a[100]; int dx,dy; bool ju; void move(int x,int y) { rep(i,1,t1) { int dl=0,dr=0,il=0,ir=0; if(a[i].idx=="DR") { rep(j,1,a[i].n) { if(a[i].arr[j]==x) {ju=true;return ;} if(a[i].arr[j]<x) dr++; } } else if(a[i].idx=="DC") { rep(j,1,a[i].n) { if(a[i].arr[j]==y) {ju=true;return ;} if(a[i].arr[j]<y) dl++; } } else if(a[i].idx=="IR") { rep(j,1,a[i].n) { if(a[i].arr[j]<=x) ir++; } } else if(a[i].idx=="IC") { rep(j,1,a[i].n) if(a[i].arr[j]<=y) il++; } else if(a[i].idx=="EX") { if(a[i].arr[1]==x&&a[i].arr[2]==y) {x=a[i].arr[3];y=a[i].arr[4];} else if(a[i].arr[3]==x&&a[i].arr[4]==y) {x=a[i].arr[1];y=a[i].arr[2];} } x=x-dr;y=y-dl;x=x+ir;y=y+il; /*cout<<x<<" "<<y<<endl;*/ } dx=x;dy=y; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif //freopen("out.txt", "w", stdout); ios::sync_with_stdio(0),cin.tie(0); int l,r; int cnt=0; while(cin>>l>>r&&l) { cnt++; if(cnt!=1) cout<<endl; cin>>t1; rep(i,1,t1) { cin>>a[i].idx; if(a[i].idx=="EX") cin>>a[i].arr[1]>>a[i].arr[2]>>a[i].arr[3]>>a[i].arr[4]; else {cin>>a[i].n;rep(j,1,a[i].n) cin>>a[i].arr[j];} } int t2; cin>>t2; cout<<"Spreadsheet #"<<cnt<<endl; rep(i,1,t2) { int x,y; dx=0;dy=0;ju=false; cin>>x>>y; move(x,y); if(ju) cout<<"Cell data in ("<<x<<","<<y<<") GONE"<<endl; else cout<<"Cell data in ("<<x<<","<<y<<") moved to ("<<dx<<","<<dy<<")"<<endl; } } return 0; }