LYDSY模拟赛day9 2048
/* 大模拟题,做的时候思路还是比较清晰的 */ #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #define ll long long #define fo(i,l,r) for(int i = l;i <= r;i++) #define fd(i,l,r) for(int i = r;i >= l;i--) using namespace std; const int maxn = 1050; ll read(){ ll x=0,f=1; char ch=getchar(); while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}; while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}; return x*f; } int n,m; int dx[4] = {0,0,-1,1}; int dy[4] = {-1,1,0,0}; int flag[10][10]; bool vis[10][10]; ll mp[15][15],d,k,v; ll ans1,ans2; ll judge(int y,int x,ll val){ if(y < 1 || y > n || x < 1 || x > n || vis[y][x]) return -1; if(!mp[y][x]) return val; if(mp[y][x] == val) return val*2; return -1; } bool tran(int op){ memset(vis,false,sizeof(vis)); bool cg = false; int st1,ed1,dr1,st2,ed2,dr2; int ny,nx,cy,cx; ll tmp,rst; d = read(); k = read(); v = read(); if(d == 1){ st1 = n; ed1 = 1; dr1 = -1; }else{ st1 = 1; ed1 = n; dr1 = 1; } if(d == 3){ st2 = n; ed2 = 1; dr2 = -1; }else{ st2 = 1; ed2 = n; dr2 = 1; } for(int i = st1;;i += dr1){ for(int j = st2;;j += dr2){ tmp = mp[i][j]; cy = i; cx = j; if(tmp)while(1){ ny = cy + dy[d]; nx = cx + dx[d]; rst = judge(ny,nx,tmp); if(rst == -1) break; else{ cg = true; mp[cy][cx] = 0; mp[ny][nx] = rst; if(rst != tmp){ ans2 += rst; vis[ny][nx] = true; break; } cy = ny; cx = nx; } } if(j == ed2) break; } if(i == ed1) break; } if(!cg) return false; ans1++; ll r = 0; memset(flag,0,sizeof(flag)); fo(i,1,n){ fo(j,1,n){ if(!mp[i][j]) flag[i][j] = ++r; } } fo(i,1,n){ fo(j,1,n){ if(flag[i][j] == 1 + k%r) mp[i][j] = v; } } return true; } int main(){ freopen("game.in","r",stdin); freopen("game.out","w",stdout); n = read(); m = read(); int x,y,v; y = read();x = read();v = read();mp[y][x] = v; y = read();x = read();v = read();mp[y][x] = v; fo(op,1,m){ if(!tran(op)) break; } cout<<ans1<<endl<<ans2<<endl; return 0; }