【Codeforces】1104C Grid game (变异的俄罗斯方块)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/87468279

http://codeforces.com/problemset/problem/1104/C

4 X 4 的方格 放置 1*2的矩形(用1表示)和2*1的矩形(用0表示)

只要有一行或者一列都填满了,就会自动消除,就可以放心的矩形了,只要不重叠就可以,不是每一个位置都必须用到

下面我的方法,一行和二行只放垂直的,第三行放水平的,不用第四行

cnt0 和 cnt1 只起到位置标记作用

如果是垂直的矩形,输出的是上面方块的位置,水平的则输出左边方块的位置

( representing numbers of smallest row and column intersecting with it.)

#include <iostream>
#include <string>

using namespace std;

int main ()
{
	string s;
	cin >> s;
	int i = 0;
	int cnt0 = 0,cnt1 = 1;
	while(i<s.length())
	{
		if(s[i]=='0')
		{
			cnt0++; 
			if(cnt0==5)
				cnt0 = 1;
			cout << "1 " << cnt0 << endl; 
		}
		else
		{
			cnt1+=2;
			if(cnt1==5)
				cnt1 = 1;
			cout << "3 " << cnt1 << endl; 
		}
		i++;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/CSDN___CSDN/article/details/87468279