CSP俄罗斯方块(简单易懂)

开始将题目理解成了,开始的列应该是从输入图案的最左端开始计算,将前面所有的空列都删掉,代码如下:


#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
const int M = 1e5+10;
int a[20][20];
int b[5][5];

int main(){
    for(int i = 0 ; i < 15 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0 ; i < 4 ; i++){
        for(int j = 0 ; j < 4 ; j++){
            cin >> b[i][j];
        }
    }
    int k;
    cin >> k;
    int flag = 0;
    int res = 0;
    for(int i = 0 ; i < 4 ; i++){
        for(int j = 0 ; j < 4 ; j++){
            if(b[j][i] == 1){
                flag = 1;
                res = i;
                break;
            }
        }
        if(flag == 1){
            break;
        }
    }
    vector<vector<int>> c(4,vector<int>(2,0));
    int num = 0;
    for(int i = 0 ; i < 4 ; i++){
        for(int j = res ; j < 4 ; j++){
            if(b[i][j] == 1){
                c[num][0] = i;
                c[num][1] = k + j - res;
                num++;
            }
        }
    }
    int xd = 0;
    for(int i = 1 ; i < 18 ; i++){
        if(c[0][0]+i < 15 && c[1][0]+i < 15 && c[2][0]+i < 15 && c[3][0]+i < 15 && a[c[0][0]+i][c[0][1]] == 0 && a[c[1][0]+i][c[1][1]] == 0 && a[c[2][0]+i][c[2][1]] == 0 && a[c[3][0]+i][c[3][1]] == 0){
            xd++;
        }
        else{
            break;
        }
    }
    for(int i = 0 ; i < 4 ; i++){
        a[c[i][0]+xd][c[i][1]] = 1;
    }
    for(int i = 0 ; i < 15 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

结果只拿到了60分。

仔细看题,题目里写的是,只删除最左端的列,也就是说不管图案在哪里,都只删除最左端的一列。比如说输入的图案是
0 0 0 1
0 0 0 1
0 0 0 1
0 0 0 1
,也只删除最左列,即从第k列开始放的图案是
0 0 1
0 0 1
0 0 1
0 0 1,
得到的图案是这样的:
在这里插入图片描述

逆天了,我只能说CSP的出题人完全不靠谱

100分代码:

#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
const int M = 1e5+10;
int a[20][20];
int b[5][5];

int main(){
    for(int i = 0 ; i < 15 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            cin >> a[i][j];
        }
    }
    int num = 0;
    vector<vector<int>> c(4,vector<int>(2,0));
    for(int i = 0 ; i < 4 ; i++){
        for(int j = 0 ; j < 4 ; j++){
            cin >> b[i][j];
            if(b[i][j] == 1){
                c[num][0] = i;
                c[num][1] = j;
                num++;
            }
        }
    }
    int k;
    cin >> k;
    for(int i = 0 ; i < 4 ; i++){
        c[i][1] += k - 1;
    }
    int xd = 0;
    for(int i = 1 ; i < 18 ; i++){
        if(c[0][0]+i < 15 && c[1][0]+i < 15 && c[2][0]+i < 15 && c[3][0]+i < 15 && a[c[0][0]+i][c[0][1]] == 0 && a[c[1][0]+i][c[1][1]] == 0 && a[c[2][0]+i][c[2][1]] == 0 && a[c[3][0]+i][c[3][1]] == 0){
            xd++;
        }
        else{
            break;
        }
    }
    for(int i = 0 ; i < 4 ; i++){
        a[c[i][0]+xd][c[i][1]] = 1;
    }
    for(int i = 0 ; i < 15 ; i++){
        for(int j = 0 ; j < 10 ; j++){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值