CCF俄罗斯方块-2&&模拟练习

7 篇文章 0 订阅

(⊙﹏⊙)这道题不会做呀~然后去观摩了各种大佬的作品才理解了思路QAQ

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int grid[18][16];
int temp, col;

struct node
{
    int x, y;
}a[4];
//这里不要排序也可以
//bool cmp(node a, node b)
//{
//    return a.x > b.x;
//}
//检查在下落的过程中是否被阻碍
bool check(int r)
{
    for(int i=0; i<4; i++)
    {
        if(grid[r+a[i].x][col+a[i].y])
            return false;
    }
    return true;
}

int main()
{
    for(int i=0; i<15; i++)
        for(int j=0; j<10; j++)
        scanf("%d", &grid[i][j]);
        //在最下面补了一层
        for(int i=0; i<10; i++)
            grid[15][i] = 1;
            
        int Count = 0;
        //获取输入图形的坐标,这里其实不需要排序jiuok
    for(int i=0;i<4; i++)
    {
        for(int j=0; j<4; j++)
        {
            scanf("%d", &temp);
            if(temp)
            {
                a[Count].x = i;
                a[Count].y = j;
                Count++;
            }
        }
    }

//    sort(a, a+4, cmp);
//    for(int i=0; i<4; i++)
//        cout << a[i].x << " " << a[i].y << endl;
    scanf("%d", &col);
    //因为我的列是从0开始的
    col--;
    //最后放置图形的行
    int loc;
    for(int i=0; i<=14&&check(i); i++)
        loc = i;
        
    for(int i=0; i<4; i++)
    grid[loc+a[i].x][col+a[i].y] = 1;
    
    for(int i=0; i<15; i++)
    {
        for(int j=0; j<10; j++)
        if(j==9)
        cout << grid[i][j] ;
        else cout << grid[i][j] << " ";
        cout << endl;
    }
    return 0;
}

***********************************************************************************************************************************************
下面也是一道模拟题

input

output


Sample Input
Sample Input 1
1
1 2 3 4 5 6
Sample Input 2
2
1 2 3 4 5 6
1 3 5 4 8 10
Sample Output
Sample Output 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
2 2 2 1 1 1 2 2 2 2
2 2 2 1 1 1 2 2 2 2
2 2 2 1 1 1 2 2 2 2
2 2 2 1 1 1 2 2 2 2
2 2 2 1 1 1 2 2 2 2
2 2 2 1 1 1 2 2 2 2
2 2 2 1 1 1 2 2 2 2
Sample Output 2
1 1 1 1 1 1 1 1 1 1
2 2 2 1 2 2 2 1 2 1
1 1 1 1 1 1 1 1 1 1
3 3 3 1 2 2 3 1 3 1
1 1 1 1 1 1 1 1 1 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1

这就是个简单的模拟题吧

我做的:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int grid[11][11];
int row[4], col[4];
int main()
{
    memset(grid, 0, sizeof(grid));
    memset(row, 0, sizeof(row));
    memset(col, 0, sizeof(col));
    int k;
    cin >> k;
    int temp = k;
    while(temp--)
    {
        for(int i=0; i<3; i++)
            scanf("%d", row+i);//1 2 3

        for(int i=0; i<3; i++)
            scanf("%d", col+i);// 4 5 6

        for(int i=0;i<3;i++)
            for(int j=0; j<10; j++)
            grid[row[i]-1][j] = temp+1;

            for(int i=0; i<10; i++)
                for(int j=0; j<3; j++)
                grid[i][col[j]-1] = temp+1;

    }
    for(int i=0; i<10; i++)
    {
        for(int j=0; j<10; j++)
        {
            if(!grid[i][j])
                grid[i][j] = k+1;
                if(j==9)
                cout << grid[i][j];
                else
            cout << grid[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}
***********************************************大佬做的******************************************************************************************

对比之下明显技不如人QAQ

#include <iostream>
#include <cstring>
using namespace std;
int hang[11], lie[11]; 
int main()
{
    memset(hang, 0, sizeof(hang));
    memset(lie, 0, sizeof(lie));
    int n, n1;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            scanf("%d", &n1);
            hang[n1] = i;
        }
        for(int j = 0; j < 3; j++)
        {
            scanf("%d", &n1);
            lie[n1] = i;
        }
    }
    for(int i = 1; i < 11; i++)
    {
        printf("%d", n + 1 - ((hang[i] > lie[1]) ? hang[i] : lie[1]));
        for(int j = 2; j < 11; j++)
            printf(" %d", n + 1 - ((hang[i] > lie[j]) ? hang[i] : lie[j]));
        printf("\n");        
    }
    return 0;
}
/* 
1 1 1 1 1 1 1 1 1 1
2 2 2 1 2 2 2 1 2 1
1 1 1 1 1 1 1 1 1 1
3 3 3 1 2 2 3 1 3 1
1 1 1 1 1 1 1 1 1 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1
3 3 3 1 2 2 3 1 3 1 
/*
2
1 2 3 4 5 6
1 3 5 4 8 10

1
1 2 3 4 5 6
*/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值