(⊙﹏⊙)这道题不会做呀~然后去观摩了各种大佬的作品才理解了思路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> for(int i=0; i<3; i++) for(int i=0;i<3;i++) for(int i=0; i<10; i++) } 对比之下明显技不如人QAQ #include <iostream> 1
|