大致题意: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. Windows的公共控件窗口类列表

    The following window class names are provided by the common control library: ANIMATE_CLASS Creates a ...

  2. Android有效解决加载大图片时内存溢出的问题

    首先,您需要了解一下,图片占用内存的计算方法,传送门:http://blog.csdn.net/scry5566/article/details/11568751 尽量不要使用setImageBitm ...

  3. AsyncTask简单入门

    关系: java.lang.Object    ↳    android.os.AsyncTask<Params, Progress, Result> 概述: AsyncTask是Andr ...

  4. SICP练习1.6-1.8

    1.6 死循环 1.7 #lang racket (define (square x) (* x x)) (define (sqrt-iter guess x) (if (good-enough? g ...

  5. libevent: linux安装libevent

    http://libevent.org/上下载最新的libevent, 如 libevent-2.0.22-stable.tar.gz. 然后解压,按照README里面的步骤安装.

  6. java--进步学习IO

    import java.io.*; public class Demo1 { public static void main(String []args) throws Exception{ File ...

  7. 高级UIKit-10(UDPSocket)

    [day1201_UDPSocket]:utpsocket的使用 使用UDP网络传输,是一种无连接的传输协议,不安全,一般使用在监控视频中或QQ聊天中,该网络传输就向广播传播模式,一对多. 在ios中 ...

  8. Win7 和 MAC 系统通过VMware共享文件夹(简单又好用,几乎什么都不用设置)

    Win7是Server,Mac是Client,VMware上运行Mac系统 1.在VMware的Options菜单中选择Shared Folders选项 2.选择Always enabled选项 3. ...

  9. Android如何监听蓝牙耳机的按键事件

    写在前面: 直接想要代码很简单,你直接把滚动条拉到最底端就可以看到.如果想要十分地了解为什么,那就按照我规划的一步一步来理解.以下测试环境以手头上有的「Bluedio + 红米手机」. 1.蓝牙耳机的 ...

  10. PHP - 防止非法调用页面

    这是在服务器内部: 首先定义一个常量 在调用页面的时候,检测是否存在此常量 如果存在,则调用 否则,做出提示. 创建常量: 创建常量的函数名称: define //创建一个常量,以便于页面调用,从主页 ...