Codeforces-C-Grid game(思维)

本文介绍了一款基于4x4网格的游戏,玩家需按序列放置2x1或1x2的瓷砖,目标是在不交叉的情况下放置所有瓷砖并删除满行或满列。通过特定策略,文章提供了一个示例解决方案,展示了如何避免交叉并完成游戏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time independently). You can place tile in the grid at any position, the only condition is that tiles (and tile parts) should not overlap. Your goal is to proceed all given figures and avoid crossing at any time.

Input

The only line contains a string ss consisting of zeroes and ones (1≤|s|≤10001≤|s|≤1000). Zero describes vertical tile, one describes horizontal tile.

Output

Output |s||s| lines — for each tile you should output two positive integers r,cr,c, not exceeding 44, representing numbers of smallest row and column intersecting with it.

If there exist multiple solutions, print any of them.

Example

input

Copy

010

output

Copy

1 1
1 2
1 4

Note

Following image illustrates the example after placing all three tiles:

Then the first row is deleted:

思路:我们可以建立两个数组,如果是0我们就把它放在第一列的两个位置,满了就消去,如果是1我们就放在最右边两列,满了就消去

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
string str;
int main()
{
	int a[2][2]={1,1,3,1};
	int b[4][2]={1,3,2,3,3,3,4,3};
	cin>>str;
	int len=str.length();
	int s1=0;
	int s2=0;
	for(int t=0;t<len;t++)
	{
		if(str[t]=='0')
		{
			cout<<a[s1][0]<<" "<<a[s1][1]<<endl;
			s1++;
		}
	    if(str[t]=='1')
		{
			cout<<b[s2][0]<<" "<<b[s2][1]<<endl;
			s2++;
		}
		if(s1==2)
		{
			s1=0;
		}
		if(s2==4)
		{
			s2=0;
		}
	}
	
	
	return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

black-hole6

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值