题目链接:Grid game

题目原文

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.

题目大意

给一个4x4的格子,在上面放置1x2或者2x1的方块。如果方块占满了一行或者一列,就可以消除这一行或者这一列。问放置方块的方案。

思路

一开始想的是,直接放,找到第一个能放的位置就放下来,但是这个思路在test14会WA。这个思路的问题在于,消去的过程中可能会产生几个孤立的点,影响后续的放置。解决办法是只要竖着放置的方块和横着放置的方块互不干扰,两个横排的和四个竖排的能自己相消,就不会产生孤立的不能放的地方。也就是用两排专门横放,两排专门竖放就可以了。直接改一下循环时候的界限就AC了。(不过这样的话代码就比较乱了)

题解

 #include <iostream>
#include <cstring> using namespace std; int map[][];
string s; void detect(int x)
{
bool flag = true;
for(int i = ; i < ; i++)
{
if(map[x][i] == ) flag = false;
}
if(flag)
{
for(int i = ; i < ; i++)
{
map[x][i] = ;
}
return;
}
flag = true;
for(int i = ; i < ; i++)
{
if(map[i][x] == ) flag = false;
}
if(flag)
{
for(int i = ; i < ; i++)
{
map[i][x] = ;
}
return;
}
} void put(char c)
{
if(c == '')
{
for (int j = ; j < ; ++j)
{
for (int k = ; k < ; ++k)
{
if(!map[j][k] && !map[j+][k])
{
map[j][k] = ;
map[j+][k] = ;
cout << j+ << " " << k+ << endl;
detect(j);
detect(k);
detect(j+);
return;
}
}
}
}
else
{
for (int j = ; j < ; ++j)
{
for (int k = ; k < ; ++k)
{
if(!map[j][k] && !map[j][k+])
{
map[j][k] = ;
map[j][k+] = ;
cout << j+ << " " << k+ << endl;
detect(j);
detect(k);
detect(k+);
return;
}
}
}
}
} int main()
{
cin >> s;
for(int i = ; i < s.length(); i++)
{
put(s[i]);
}
}

格子游戏Grid game CodeForce#1104C 模拟的更多相关文章

  1. 1647: [Usaco2007 Open]Fliptile 翻格子游戏

    1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 423  Solved: 173[ ...

  2. [Usaco2007 Open]Fliptile 翻格子游戏

    [Usaco2007 Open]Fliptile 翻格子游戏 题目 Farmer John knows that an intellectually satisfied cow is a happy ...

  3. Fliptile 翻格子游戏

    问题 B: [Usaco2007 Open]Fliptile 翻格子游戏 时间限制: 5 Sec  内存限制: 128 MB 题目描述 Farmer John knows that an intell ...

  4. [BZOJ 1647][USACO 2007 Open] Fliptile 翻格子游戏

    1647: [Usaco2007 Open]Fliptile 翻格子游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 702  Solved: 281[ ...

  5. [Usaco2007 Open]Fliptile 翻格子游戏题解

    问题 B: [Usaco2007 Open]Fliptile 翻格子游戏 时间限制: 5 Sec  内存限制: 128 MB 题目描述 Farmer John knows that an intell ...

  6. codevs 5972 格子游戏

    5972 格子游戏  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Description Alice和Bob玩了一个古老的游戏:首先画一个n * ...

  7. 格子游戏x(并查集)

    格子游戏 [问题描述] Alice和Bob玩了一个古老的游戏:首先画一个n * n的点阵(下图n = 3) 接着,他们两个轮流在相邻的点之间画上红边和蓝边:           直到围成一个封闭的圈( ...

  8. 【BZOJ 1647】[Usaco2007 Open]Fliptile 翻格子游戏 模拟、搜索

    第一步我们发现对于每一个格子,我们只有翻和不翻两种状态,我们发现一旦确定了第一行操作,那么第二行的操作也就随之确定了,因为第一行操作之后我们要想得到答案就得把第一行全部为0,那么第二行的每一个格子的操 ...

  9. Kilani and the Game-吉拉尼的游戏 CodeForce#1105d 模拟 搜索

    题目链接:Kilani and the Game 题目原文 Kilani is playing a game with his friends. This game can be represente ...

随机推荐

  1. 常用Linux备份

    用于备份的Tar 备份工具Tar是以前备份文件的可靠方法,几乎可以工作于任何环境中,Linux老用户一般都信赖它. Linux中以.tar结尾的文件都是用tar创建的.它的使用超出了单纯的备份,可用来 ...

  2. 安装yarn集群

    安装yarn集群 # mapreduce运行平台YARN mapreduce程序应该是在很多机器上并行启动,而且先执行map task,当众多的maptask都处理完自己的数据 后,还需要启动众多的r ...

  3. MySQL如何选择合适的索引

    先来看一个栗子 EXPLAIN select * from employees where name > 'a'; 如果用name索引查找数据需要遍历name字段联合索引树,然后根据遍历出来的主 ...

  4. 骑士精神(IDA*)

    题目描述 输入格式 第一行有一个正整数T(T<=10),表示一共有N组数据.接下来有T个5×5的矩阵,0表示白色骑士,1表示黑色骑士,*表示空位.两组数据之间没有空行. 输出格式 对于每组数据都 ...

  5. codeforces C. Sonya and Problem Wihtout a Legend(dp or 思维)

    题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i ...

  6. poj 2253 Frogger(floyd变形)

    题目链接:http://poj.org/problem?id=1797 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路 ...

  7. POJ 3083 Children of the Candy Corn (DFS + BFS)

    POJ-3083 题意: 给一个h*w的地图. '#'表示墙: '.'表示空地: 'S'表示起点: 'E'表示终点: 1)在地图中仅有一个'S'和一个'E',他们为位于地图的边墙,不在墙角: 2)地图 ...

  8. 实现 Java 本地缓存,该从这几点开始

    缓存,我相信大家对它一定不陌生,在项目中,缓存肯定是必不可少的.市面上有非常多的缓存工具,比如 Redis.Guava Cache 或者 EHcache.对于这些工具,我想大家肯定都非常熟悉,所以今天 ...

  9. 理解Yarn的执行流程和组件作用

    Yarn引入案例 1.学生找院长报到,院长给学生一个学号 2.院长比较忙,继续找主任处理学生事务 3.系主任找院办给学生分配资源(书本) 4.主任找张老师教授java 5.张老师给学生安排座位 6.学 ...

  10. java解决回文数

    递归解决palindrome问题 如果String仅仅只是一个或者0个字符,则它就是palindrome 否则比较字符串第一个和最后一个字符 如果第一个和最后一个字符不同,那么就不是palindrom ...