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
- codeforces101156L——Super 2048
- python—super
- Cobra —— super dis
- Java——Super关键字
- OC语言— super用法
- LeetCode—372. Super Pow
- java关键字之—super
- Java——this 和 super
- 黑马程序员——super的使用
- hdu 4417——Super Mario
- JAVA小知识——super()函数
- Java基础知识——super关键字
- hdu1087——Super Jumping! Jumping! Jumping!
- JAVA_SE基础——40.super关键字
- Java关键字——super、this
- java学习日记——super关键字
- 面向对象——this和super
- UVA 12298——Super Poker II
- org.hibernate.MappingException: Unknown entity
- js中将json字符串转换为json对象的方法
- Google android的产品线及总体架构
- IntelliJ IDEA 中如何查看一个类的所有继承关系(当前类的所有继承关系图)
- js窗口震动小程序
- codeforces101156L——Super 2048
- supervisor-进程管理工具
- 添加自定义alias命令
- 观察者模式
- CodeForces 585E
- Junit、Assert、内省、Properties类与配置文件的使用
- C/C++的中缀转后缀并求值的实现
- ViewPager 详解(三)---PagerTabStrip与PagerTitleStrip添加标题栏的异同
- Fast-RCNN代码解读(1)