题目链接: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. Keras实例教程(1)

    https://blog.csdn.net/baimafujinji/article/details/78384792

  2. vi 多行注释与取消

    多行注释 1.在命令行模式下,按 Shift + v 进入 VISUAL LINE 模式 2.选择要注释内容 3.按下 Ctrl + Shift + v 锁定块(XShell中) 或 按下 Ctrl ...

  3. 做「容量预估」可没有true和false

    如果第二次看到我的文章,欢迎右侧扫码订阅我哟~ 

  4. 《Java 8 in Action》Chapter 9:默认方法

    传统上,Java程序的接口是将相关方法按照约定组合到一起的方式.实现接口的类必须为接口中定义的每个方法提供一个实现,或者从父类中继承它的实现. 但是,一旦类库的设计者需要更新接口,向其中加入新的方法, ...

  5. Python--函数参数类型、用法及代码示例

    在编程语言里,将一个个功能定义成函数,能够进行反复调用,而不是每次都重复相同的代码,这种方式能够大幅度降低代码的复杂度. 函数的好处: 1.代码重用 2.保持一致性 3.可扩展性 1.基础 我们定义函 ...

  6. 【Linux命令】modprobe命令

    modprobe(module probe)命令 用于自动处理可载入模块. 1)语法 modprobe [-acdlrtvV][--help][模块文件][符号名称 = 符号值] 2)补充 modpr ...

  7. 检查python标识符是否有效

  8. 2019dx#9

    Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Rikka with Quicksort 25.85%(38/147)   1002 Ri ...

  9. 2018CCPC 吉林现场赛 赛后总结

    一直以来都没有比赛完写总结的习惯,导致前面几次比赛都没有写过总结. 这是我写的第一场总结把,有时间有想法还记得细节的话再把前面几次比赛的总结给补上把. 热身赛: 热身赛的时候,写的比较急想着快点做出题 ...

  10. CF1036C Classy Numbers dfs+二分

    Classy Numbers time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...