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了要先判断 ...
随机推荐
- IOS7修改Navigation Bar上的返回按钮文本颜色,箭头颜色以及导航栏按钮的颜色
解决方法 1: 自从IOS7后UINavigationBar的一些属性的行为发生了变化.你可以在下图看到: 现在,如果你要修改它们的颜色,用下面的代码: 1 2 3 4 self.navigation ...
- SMTP邮件传输协议发送邮件和附件(转)
1. SMTP 常用命令简介 1). SMTP 常用命令 HELO/EHLO 向服务器标识用户身份 MAIL 初始化邮件传输 mail from: RCPT 标识单个的邮件接收人:常在MAIL ...
- Windows系统命令行net user命令用法
在Windows渗透测试过程中,最常用的要数net user 命令了,但是非常多的时候我们都是对Linux命令非常熟悉,对Windows命令非常熟悉或者了解用法的少只有少,为了以后工作方便,这里记录一 ...
- Java, C#, Swift语法对比速查表
原文:Java, C#, Swift语法对比速查表 Java 8 C# 6 Swift 变量 类型 变量名; 类型 变量名; var 变量名 : 类型; 变量(类型推断) N/A var 变量名= ...
- Json也可以这么使
public string GetJSON() { //Json数据 string json112 = "{\"control_info\":{\"imei\& ...
- aop编程 环绕round
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Python 绝对简明手册
Python 绝对简明手册 help(函数名)来获取相关信息 另外,自带的文档和google也是不可少的 2. 基本语法2.1. if / elif / else x=int(raw_input(&q ...
- 自定义的Server
自定义的Server 我们在上面对ASP.NET Core默认提供的具有跨平台能力的KestrelServer进行了详细介绍(<聊聊ASP.NET Core默认提供的这个跨平台的服务器——Kes ...
- CVPapers论文整理工具-开源
一.工具介绍及运行实例 相信计算机视觉领域的同道中人都知道这个Computer Vision Resource网站, http://www.cvpapers.com/ 网页部分截图如下: 可以看到有 ...
- Java 多线程-生产者、消费者
一.整体代码 ThreadDemo.java public class ThreadDemo { public static void main(String[] args) { Godown god ...