codeforces101156L——Super 2048

来源:互联网 发布:sql商务系统开发培训 编辑:程序博客网 时间:2024/06/07 09:20

1、题意:给你一个2048游戏的图,然后问你向上下左右某一种操作后结果是什么,不明白啥意思的给你游戏…
2、分析:这题其实是个水题,只不过处理的方式值得一谈。。上下左右方向在旋转之后其实方式是一样的。旋转之后暴力求值。

 #include <map>#include <set>#include <cmath>#include <queue>#include <vector>#include <bitset>#include <string>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define M 110#define LL long long#define MOD 1000000007#define inf 2147483647#define llinf 4000000000000000000ll#define For(i, x, y) for(int i = (x); i < (y); i ++)#define rep(i, x, y) for(int i = (x); i <= (y); i ++)#define drep(i, x, y) for(int i = (x); i >= (y); i --)inline int read(){    char ch=getchar();int x=0,f=1;    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}    return x*f;}inline LL llread(){    char ch=getchar();LL x=0,f=1;    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();}    return x*f;}int a[M][M], b[M][M], n;inline void rotate(){    rep(i, 1, n) rep(j, 1, n) b[j][n + 1 - i] = a[i][j];    rep(i, 1, n) rep(j, 1, n) a[i][j] = b[i][j];}inline void solve(){    rep(i, 1, n) drep(j, n, 1){        drep(k, j, 1){            if(a[i][k]){                swap(a[i][j], a[i][k]);                break;            }        }        drep(k, j - 1, 1){            if(a[i][k]){                if(a[i][k] == a[i][j]) a[i][j] *= 2, a[i][k] = 0;                break;            }        }    }}inline void print(){    rep(i, 1, n){        rep(j, 1, n) cout << a[i][j] << " ";        cout << endl;    }}int main(){    //freopen("0input.in", "r", stdin);    int T = read();    while(T --){        n = read(); string str; cin >> str;        rep(i, 1, n) rep(j, 1, n) cin >> a[i][j];        if(str == "up") rotate();        else if(str == "left") rotate(), rotate();        else if(str == "down") rotate(), rotate(), rotate();        solve();        if(str == "up") rotate(), rotate(), rotate();        else if(str == "left") rotate(), rotate();        else if(str == "down") rotate();        print();    }    return 0;}
0 0
原创粉丝点击