jzoj 2050. 【8.18】2048
来源:互联网 发布:用户行为分析 算法 编辑:程序博客网 时间:2024/05/01 18:57
题目描述
此时,Conan却在一旁玩着2048。
这是一个4*4的矩阵,初始全为0。每次一个没有数字的格子中会随机出现一个2或4,每次可以选择上下左右其中一个方向去滑动,每滑动一次,所有的数字方块都会往滑动的方向靠拢外,相同数字的方块在靠拢、相撞时会相加。
Conan想看看今天自己运气咋样,于是就闭着眼睛,在屏幕上随便滑来滑去。所以这个模拟的任务就交给你了。过了一会,他然后睁开眼睛,如果游戏没有结束(滑动后如果没有空格子,则游戏结束),请输出矩阵(格式参见样例),否则输出“Game over!”(不包含引号)。
输入
从文件 game.in 中读入数据。
输入第一行包含一个整数N,表示Conan滑了几下。
接下来N 行,x, y, v, f表示第x行与第y列出现数字为v后,Conan滑的方向为f(f为字符,U, D, L, R分别表示向上下左右滑)。
行从上往下1-4标号,列从左往右1-4标号。
数据保证在游戏未结束时,只会在空白区域出现数字。
输出
输出到文件 game.out 中。
输出按题目描述。
思路
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
变态的模拟题(ノ=Д=)ノ┻━┻
手动强行模拟就可以了
只是细节很难而已
#include <stdio.h>#include <string>#include <cstring>int a[5][5],b[5][5];bool f[5],f1,f2;using namespace std;__attribute__((optimize("O2")))int main(){ freopen("2048.in","r",stdin); freopen("2048.out","w",stdout); memset(a,0,sizeof(a)); int n,m,x,y,v,i,j,k,l,o,xx,yr; char ch[2]; scanf("%d",&n); for (i=1;i<=n;i++) { f1=false; scanf("%d%d%d%s",&x,&y,&v,&ch); if (a[x][y]==0) f1=true; a[x][y]=v; if (i==11) { yr++; } if (ch[0]=='U') { for (j=1;j<=4;j++) { for (l=4;l>=1;l--) { if (a[l][j]==0) for (o=l;o<=4;o++) { if (o+1<=4) { f1=true; a[o][j]=a[o+1][j]; a[o+1][j]=0; } } } for (k=1;k<=4;k++) { for (l=k;l>=1;l--) { if (a[l][j]==0) for (o=l;o<=4;o++) { if (o+1<=4) { f1=true; a[o][j]=a[o+1][j]; a[o+1][j]=0; } } } for (xx=1;xx<=4;xx++) if (a[xx][j]==a[xx+1][j]&&a[xx][j]!=0&&f[xx]==false&&f[xx+1]==false&&xx+1<=4) { f1=true; f[xx]=true; f[xx+1]=true; a[xx][j]=a[xx][j]*2; a[xx+1][j]=0; } } for (xx=1;xx<=4;xx++) f[xx]=false; } } else if (ch[0]=='D') { for (j=1;j<=4;j++) { for (l=1;l<=4;l++) { if (a[l][j]==0) for (o=l;o>=1;o--) { f1=true; a[o][j]=a[o-1][j]; a[o-1][j]=0; } } for (k=4;k>=1;k--) { for (l=1;l<=k;l++) { if (a[l][j]==0) for (o=l;o>=1;o--) { f1=true; a[o][j]=a[o-1][j]; a[o-1][j]=0; } } for (xx=4;xx>=1;xx--) if (a[xx][j]==a[xx-1][j]&&a[xx][j]!=0&&f[xx]==false&&f[xx-1]==false&&xx-1>=1) { f1=true; f[xx]=true; f[xx-1]=true; a[xx][j]=a[xx][j]*2; a[xx-1][j]=0; } } for (xx=1;xx<=4;xx++) f[xx]=false; } } else if (ch[0]=='L') { for (j=1;j<=4;j++) { for (l=4;l>=1;l--) { if (a[j][l]==0) for (o=l;o<=4;o++) { if (o+1<=4) { f1=true; a[j][o]=a[j][o+1]; a[j][o+1]=0; } } } for (k=1;k<=4;k++) { for (l=k;l>=1;l--) { if (a[j][l]==0) for (o=l;o<=4;o++) { if (o+1<=4) { f1=true; a[j][o]=a[j][o+1]; a[j][o+1]=0; } } } for (xx=1;xx<=4;xx++) { if (a[j][xx]==a[j][xx+1]&&a[j][xx]!=0&&f[xx]==false&&f[xx+1]==false&&xx+1<=4) { f1=true; f[xx]=true; f[xx+1]=true; a[j][xx]=a[j][xx]*2; a[j][xx+1]=0; } } } for (xx=1;xx<=4;xx++) f[xx]=false; } } else if (ch[0]=='R') { for (j=1;j<=4;j++) { for (l=1;l<=4;l++) { if (a[j][l]==0) for (o=l;o>=1;o--) { f1=true; a[j][o]=a[j][o-1]; a[j][o-1]=0; } } for (k=4;k>=1;k--) { for (l=1;l<=k;l++) { if (a[j][l]==0) for (o=l;o>=1;o--) { f1=true; a[j][o]=a[j][o-1]; a[j][o-1]=0; } } for (xx=4;xx>=1;xx--) if (a[j][xx]==a[j][xx-1]&&a[j][xx]!=0&&f[xx]==false&&f[xx-1]==false&&xx-1>=1) { f1=true; f[xx]=true; f[xx-1]=true; a[j][xx]=a[j][xx]*2; a[j][xx-1]=0; } } for (xx=1;xx<=4;xx++) f[xx]=false; } } } if (!f1) printf("Game over!"); else for (i=1;i<=4;i++) { for (j=1;j<=4;j++) printf("%d ",a[i][j]); printf("\n"); }}
1 0
- jzoj 2050. 【8.18】2048
- jzoj 2050. 【8.18】游戏
- jzoj 2048. 【8.18】跳格子
- jzoj 2051. 【8.18】极其简单的最短路问题
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C
- [JZOJ 3424] 粉刷匠 && [JZOJ 4254] 集体照
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
- [JZOJ 1280]最大匹配
- [JZOJ 1281]旅行
- [1282 JZOJ]资源勘探
- [JZOJ 1283]排序统计
- JZOJ NOIP2014模拟 8.12
- JZOJ NOIP2014模拟 8.13
- [JZOJ 1598]文件修复
- 【JZOJ 3111】单词查找
- 【JZOJ 3112】开会
- JZOJ 3463 军训
- 清理数据库日志的办法
- Java数组的应用:案例:杨辉三角,三维数组,字符串数组
- poj-2352【Stars】
- 【Python 01】使用UE配置Python编程环境
- 关于分布式事务、两阶段提交、一阶段提交、Best Efforts 1PC模式和事务补偿机制的研究
- jzoj 2050. 【8.18】2048
- .在重新部署了oozie-site.xml之后,不能够寻找到工作流作业对应的hadoop jobid
- C# 利用log4net 把日志写入到数据库
- Spring MVC 框架入门-Hello World 实例
- pod 引用第三方库文件报错 library not found for -lMJRefresh
- docker 容器管理常用命令
- Android SQLite数据库(事务)的使用,多线程CRUD并发操作(可用于实际开发)
- Android使用monkey进行简单测试
- 侧滑