Problem D: Flip Five
大致题意: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的更多相关文章
- hdu 4146 Flip Game
Flip Game Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- HDOJ-三部曲-1001-Flip Game
Flip Game Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Su ...
- Petrozavodsk Winter Training Camp 2018
Petrozavodsk Winter Training Camp 2018 Problem A. Mines 题目描述:有\(n\)个炸弹放在\(x\)轴上,第\(i\)个位置为\(p_i\),爆炸 ...
- POJ1753 Flip Game(bfs、枚举)
链接:http://poj.org/problem?id=1753 Flip Game Description Flip game is played on a rectangular 4x4 fie ...
- poj1753 Flip Game
题意:4*4的正方形,每个格子有黑白两面,翻转格子使得4*4个格子显示全黑或全白,翻转要求:选中的那个格子,以及其上下左右相邻的格子(如果存在)要同时翻转.输出最小的达到要求的翻转次数或者Imposs ...
- Gambler's Ruin Problem and 3 Solutions
In my stochastic processes class, Prof Mike Steele assigned a homework problem to calculate the ruin ...
- NYOJ:题目529 flip
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=529 由于此题槽点太多,所以没忍住...吐槽Time: 看到这题通过率出奇的高然后愉快的进 ...
- Flip Game I && II
Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...
- 枚举 POJ 1753 Flip Game
题目地址:http://poj.org/problem?id=1753 /* 这题几乎和POJ 2965一样,DFS函数都不用修改 只要修改一下change规则... 注意:是否初始已经ok了要先判断 ...
随机推荐
- Chapter 13 建造者模式
建造者模式又叫生成器模式:将一个产品的内部表象与产品的生成过程分割开来,从而可以使一个建造过程生成具有不同的内部表象的产品对象. 代码: package xiao; import java.util. ...
- jQuery带有定时器的tab栏切换
现在网上很多类似选项卡的切换,我们成为tab栏切换,比如下图: 新浪的tab栏切换 淘宝的tab栏切换 其中,新浪的tab栏鼠标放上去,可以快速的来回切换,但是如果采取ajax异步传输,不停去加载服务 ...
- 解决TCP网络传输“粘包”问题
当前在网络传输应用中,广泛采用的是TCP/IP通信协议及其标准的socket应用开发编程接口(API).TCP/IP传输层有两个并列的协议:TCP和UDP.其中TCP(transport contro ...
- Json也可以这么使
public string GetJSON() { //Json数据 string json112 = "{\"control_info\":{\"imei\& ...
- Sereja and Bottles
http://codeforces.com/problemset/problem/315/A 题目意思是第ai的瓶子能开bi的瓶子.给你相应的数据,求无法用其他瓶子打开的数量(即需要外力). 一开始看 ...
- StrPos,StrScan,
Delphi提供的字符串函数里有一个Pos函数,它的定义是: function Pos(Substr: string; S: string): Integer; 它的作用是在字符串S中查找字符串Sub ...
- first-,second- and third-class value
In computer science, a programming language is said to have first-class functions if it treats funct ...
- Android 程式开发:(廿一)消息传递 —— 21.3 使用Intent发送短信
使用SmsManager类,可以在自己编写的程序内部发送短信,而不需要调用系统的短信应用. 然而,有的时候调用系统内置的短信应用会更加方便. 这时,需要使用一个MIME类型为vnd.android-d ...
- 饭卡(HDOJ2546)
饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- c++,初始化列表
类对象的构造顺序是这样的: a.分配内存,调用构造函数时,隐式/显示的初始化各数据成员 b.进入构造函数后在构造函数中执行一般计算 1.初始化类的成员有两种方式,一是使用初始化列表,二是在构造函数体内 ...