CCF认证 俄罗斯方块下落问题

CCF认证  俄罗斯方块下落问题

看这个问题感觉很蒙蔽,想了半天想了个思路:从第五行开始取出每行的对应的四列数据存到一个数组,然后判断这个数组和下落图形的二维数组的哪一行存在,上下相邻都是1的情况,如果存在的话,分别记住这是两个图形的第几行,然后对应的行相加。然后结果只有80分,有一个bug就是处理当图形数组的最后一行全是零的情况,不知怎么办就这样吧。

import java.util.Scanner;
//俄罗斯方块
public class Main {


public static void main(String[] args) {



new Main().run();
}
public void run(){
Scanner in = new Scanner(System.in);
int[][] data = new int[15][10];
for(int i=0;i<15;i++){
for(int j=0;j<10;j++){
data[i][j] = in.nextInt();
}
}

int[][] shape = new int[4][4];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
shape[i][j] = in.nextInt();
}
}

int input = in.nextInt();
in.close();

int[] line = new int[4];
int row=0,column=0,srow=0,scolumn=0;
boolean flag = false;
outer:
for(int i=4;i<15;i++){
//获得每一行数据
int count =0;
for(int j=input-1;j<input+3;j++){
line[count] = data[i][j];
count++;
}
if(i<=12)
for(int a=3;a>=0;a--){
for(int b=0;b<3;b++){
if(line[b]==1&&line[b]==shape[a][b]){
row=i;column=input+b-1;srow=a;scolumn=b;
flag = true;break outer;
}
}
}
if(i==13)
for(int a=3;a>=1;a--){
for(int b=0;b<3;b++){
if(line[b]==1&&line[b]==shape[a][b]){
row=i;column=input+b-1;srow=a;scolumn=b;
flag = true;
break outer;
}
}
}
if(i==14)
for(int a=3;a>=2;a--){
for(int b=0;b<3;b++){
if(line[b]==1&&line[b]==shape[a][b]){
row=i;column=input+b-1;srow=a;scolumn=b;
flag = true;break outer;
}
}
}
if(i==14&&flag==false){
for(int r=11;r<15;r++){
int count1=0;
for(int c=input-1;c<input+3;c++){
data[r][c]+=shape[r-11][count1];
count1++;
}
}
}


}

if(flag==true){
int count2=0,count3=0;
switch(srow){
case 3:
for(int i=row-4;i<row;i++){
count3=0;
for(int j=input-1;j<input+3;j++){
data[i][j]+=shape[count2][count3];
count3++;
}
count2++;
}break;
case 2:
for(int i=row-3;i<row+1;i++){
count3=0;
for(int j=input-1;j<input+3;j++){
data[i][j]+=shape[count2][count3];
count3++;
}
count2++;
}break;
case 1:
for(int i=row-2;i<row+2;i++){
count3=0;
for(int j=input-1;j<input+3;j++){
data[i][j]+=shape[count2][count3];
count3++;
}
count2++;
}break;
case 0:
for(int i=row-1;i<row+3;i++){
count3=0;
for(int j=input-1;j<input+3;j++){
data[i][j]+=shape[count2][count3];
count3++;
}
count2++;
}break;
default:break;
}


}


for(int i=0;i<15;i++){
for(int j=0;j<10;j++){
System.out.print(data[i][j]+" ");
}
System.out.println();
}


}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值