大致题意:3 * 3的黑白格,在翻转的时候会本身和四周的都翻转,问最小翻转几次变成全部是白色
解题思路:把3 * 3 = 9 个格子进行全排列,然后穷举然后找翻转的最小次数

#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std;
int dr[] = {,,,-,};
int dc[] = {,,,,-};
int a[];
bool tmp[][]; void change(int s){
int x = s / ;
int y = s - x * ;
for(int i = ;i < ;i++){
int xx = x + dr[i];
int yy = y + dc[i];
if(xx >= && yy >= && xx < && yy < )
tmp[xx][yy] = !tmp[xx][yy];
}
}
bool check(){
for(int i = ;i < ;i++){
for(int j = ;j < ;j++)
if(tmp[i][j])
return false;
}
return true;
} int main()
{
#ifndef ONLINE_JUDGE
// freopen("in.in","r",stdin);
#endif
int t;
cin >> t;
while(t--){
char str[][];
for(int i = ;i < ;i++){
cin >> str[i];
}
for(int i = ;i < ;i++)
a[] = ;
int num = ;
for(int i = ;i < ( << );i++){
int cnt = ;
for(int r = ;r < ;r++){
for(int c = ;c < ;c++){
if(str[r][c] == '*')
tmp[r][c] = ;
else
tmp[r][c] = ;
}
}
for(int j = ;j < ;j++){
if(i & ( << j)){
change(j);
cnt++;
}
}
if(check()){
a[num++] = cnt;
}
}
sort(a,a+num);
cout << a[] << endl;
}
return ;
}

Code

for(int i = ;i < ( << );i++){
for(int j = ;j < ;j++){
if(i & ( << j)){
}
}
}

Problem D: Flip Five的更多相关文章

  1. hdu 4146 Flip Game

    Flip Game Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  2. HDOJ-三部曲-1001-Flip Game

    Flip Game Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Su ...

  3. Petrozavodsk Winter Training Camp 2018

    Petrozavodsk Winter Training Camp 2018 Problem A. Mines 题目描述:有\(n\)个炸弹放在\(x\)轴上,第\(i\)个位置为\(p_i\),爆炸 ...

  4. POJ1753 Flip Game(bfs、枚举)

    链接:http://poj.org/problem?id=1753 Flip Game Description Flip game is played on a rectangular 4x4 fie ...

  5. poj1753 Flip Game

    题意:4*4的正方形,每个格子有黑白两面,翻转格子使得4*4个格子显示全黑或全白,翻转要求:选中的那个格子,以及其上下左右相邻的格子(如果存在)要同时翻转.输出最小的达到要求的翻转次数或者Imposs ...

  6. Gambler's Ruin Problem and 3 Solutions

    In my stochastic processes class, Prof Mike Steele assigned a homework problem to calculate the ruin ...

  7. NYOJ:题目529 flip

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=529 由于此题槽点太多,所以没忍住...吐槽Time: 看到这题通过率出奇的高然后愉快的进 ...

  8. Flip Game I && II

    Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...

  9. 枚举 POJ 1753 Flip Game

    题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...

随机推荐

  1. Python 函数基础、有序集合、文件操作(三)

    一.set 特点: set是一个无序且不重复的元素集合访问速度快:天生解决元素重复问题 方法: 初始化 >>> s1 = set()>>> print(type(s ...

  2. Miller_Rabin、 Pollard_rho Template

    Multiply and pow Function: //计算 (a*b)%c. a,b都是ll的数,直接相乘可能溢出的 // a,b,c <2^63 ll mult_modq(ll a,ll ...

  3. Codeforces 479D - Long Jumps

    479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...

  4. atlas z 轴

    问题源自一个帖子,因为上传的图比较多,就另开了这个贴写下自己的试验结果,原帖在下面链接中 http://game.ceeger.com/forum/read.php?tid=8911#info NGU ...

  5. coreldraw圆形裁剪

    裁剪方法: http://zhidao.baidu.com/link?url=9-OuTkkr7igOHgKDOhJgU6iUYY5MeGEGdNXX8p6RGq79Im4va0UdMAmH4gSDz ...

  6. C语言中Const与指针(转载)

    一.说明指针常量.指向常量的指针和指向常量的常量指针的含义.区别和共同点 首先,以上三种概念的共同点:都指的是指针 指针也是一种变量,它存储指定类型的变量的内存地址,如char* 来声明一个字符型指针 ...

  7. mac忘记登陆密码解决

    重新启动苹果电脑,开机时按住“command”键+“S”键,(普通键盘按住win+s)会进入单用户模式, 出现像DOS一样的提示符 #root>依次输入如下三个命令:(注意空格 注意大小写) f ...

  8. Server是如何完成针对请求的监听、接收与响应1

    Server是如何完成针对请求的监听.接收与响应的[上] Server是ASP .NET Core管道的第一个节点,负责完整请求的监听和接收,最终对请求的响应同样也由它完成.Server是我们对所有实 ...

  9. WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇]

    原文:WCF技术剖析之二十五: 元数据(Metadata)架构体系全景展现[元数据描述篇] 在[WS标准篇]中我花了很大的篇幅介绍了WS-MEX以及与它相关的WS规范:WS-Policy.WS-Tra ...

  10. Windows Store Javascript项目使用高德地图、谷歌地图、百度地图API

    原文 Windows Store Javascript项目使用高德地图.谷歌地图.百度地图API 在Win8 Store 项目中可以使用的地图主要有微软的Bing Map,目前高德地图sdk也支持Wi ...