大致题意: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. String "+" 的补充说明---行粒度

    String 中“+” 的操作的补充说明 在使用“+”的时候,会创建一个StringBuilder对象,然后invokevirtual append()操作 “+”操作创建StringBuilder的 ...

  2. Nmon 性能:分析 AIX 和 Linux 性能的免费工具

    原文摘自: http://www.ibm.com/developerworks/cn/aix/library/analyze_aix/ 官网:http://www.ibm.com/developerw ...

  3. sizeof与strlen的区别 浅谈

    1.sizeof operator sizeof是C语言的一种单目操作符,如C语言的其他操作符++.- - 等,它并不是函数. Queries size of the object or type. ...

  4. Sqrt(x) 牛顿迭代法

    为了实现sqrt(x),可以将问题看成是求解\(x^2-y=0\) ,即sqrt(y)=x: 牛顿法是求解方程的近似方法,给定初始点\((x0,f(x0))\),迭代公式为: #include < ...

  5. log4cpp的初步使用

    (1)下载log4cpp的工程,编译生成lib文件和dll库 下载路径为:http://sourceforge.net/projects/log4cpp/files/latest/download 如 ...

  6. C++自增和自减运算符(--和++)

    在C和C++中,常在表达式中使用自增(++)和自减(--)运算符,他们的作用是使变量的值增1或减1,如:++i(在使用i之前,先使i的值加1,如果i的原值为3,则执行j=++i后,j的值为4)--i ...

  7. Qt核心剖析: moc

    前面我们说过,Qt 不是使用的“标准的” C++ 语言,而是对其进行了一定程度的“扩展”.这里我们从Qt新增加的关键字就可以看出来:signals.slots 或者 emit.所以有人会觉得 Qt 的 ...

  8. 查询SystemFeature的方法

    查询SystemFeature的方法可以在adb shell下敲如下的命令: dumpsys package 然后搜feature关键字. 例如,我的平台的SystemFeature,如下所示: Fe ...

  9. 关于js基础easy忘记的那些事儿

    1.Number() 通过这个函数转化后的值仅仅有两个:数值和NaN,通过parseInt也能转化为数值.可是像"134df"转化后的值为134,而Number("134 ...

  10. Android 它们的定义View它BounceProgressBar

    转载请注明出处:http://blog.csdn.net/bbld_/article/details/41246247 [Rocko's blog] 之前几天下载了非常久没用了的桌面版酷狗来用用的时候 ...