校内大模拟,赛时调了2min样例过了自信没管喜提20pts。
题面:

错误代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[5][5];
bool check()
{
for(int i=1;i<=4;i++)
{
for(int j=1;j<=4;j++)
{
if(a[i][j]==0)
{
return 0;
}
}
}
return 1;
}
signed main()
{
// freopen("game.in","r",stdin);
// freopen("game.out","w",stdout);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int x, y, v;
char f;
cin>>x>>y>>v>>f;
a[x][y]=v;
if(check())
{
cout<<"Game over!";
return 0;
}
if(f=='U')
{
for(int j=2;j<=4;j++)
{
for(int k=4;k>=1;k--)
{
int lst=j;
for(int l=j-1;l>=1;l--)
{
if(a[l][k]==0)
{
a[l][k]=a[lst][k];
a[lst][k]=0;
lst=l;
continue;
}
if(a[l][k]==a[lst][k])
{
a[l][k]+=a[lst][k];
a[lst][k]=0;
lst=l;
}
else
{
break;
}
}
}
}
}
if(f=='D')
{
for(int j=3;j>=1;j--)
{
for(int k=4;k>=1;k--)
{
int lst=j;
for(int l=j+1;l<=4;l++)
{
if(a[l][k]==0)
{
a[l][k]=a[lst][k];
a[lst][k]=0;
lst=l;
continue;
}
if(a[l][k]==a[lst][k])
{
a[l][k]+=a[lst][k];
a[lst][k]=0;
lst=l;
}
else
{
break;
}
}
}
}
}
if(f=='L')
{
for(int k=4;k>=1;k--)
{
for(int j=2;j<=4;j++)
{
int lst=j;
for(int l=j-1;l>=1;l--)
{
if(a[k][l]==0)
{
a[k][l]=a[k][lst];
a[k][lst]=0;
lst=l;
continue;
}
if(a[k][l]==a[k][lst])
{
a[k][l]+=a[k][lst];
a[k][lst]=0;
lst=l;
}
else
{
break;
}
}
}
}
}
if(f=='R')
{
for(int k=4;k>=1;k--)
{
for(int j=3;j>=1;j--)
{
int lst=j;
for(int l=j+1;l<=4;l++)
{
if(a[k][l]==0)
{
a[k][l]=a[k][lst];
a[k][lst]=0;
lst=l;
continue;
}
if(a[k][l]==a[k][lst])
{
a[k][l]+=a[k][lst];
a[k][lst]=0;
lst=l;
}
else
{
break;
}
}
}
}
}
}
// if(check())
// {
// cout<<"Game over!";
// }
// else
// {
for(int i=1;i<=4;i++)
{
for(int j=1;j<=4;j++)
{
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
// }
return 0;
}