Flip Game

一个4*4的棋盘,怎样按才能最少的按下方格,使之全白或全黑。

每个方格仅需按一遍,枚举按的16个方格按或不按。得出的结果是全黑或全白就输出即可。

dfs加枚举。

可以用位运算进行优化,目前我还不会。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

bool map[6][6]={false};
int dx[6]={-1,1,0,0,0};
int dy[6]={0,0,-1,1,0};
int step;
bool flag=false;

bool judge(void)
 {
     int i,j;
     for(i=1;i<5;i++)
         for(j=1;j<5;j++)
             if(map[i][j]!=map[1][1])
                return false;
     return true;
 }

void flip(int x,int y)
{
    for(int i=0;i<5;i++)
         map[x+dx[i]][y+dy[i]]=!map[x+dx[i]][y+dy[i]];
}

void dfs(int x,int y,int d)
{
    if(d==step)
    {
        flag=judge();
        return;
    }
    if(flag||x==5)
        return;

    flip(x,y);
    if(y<4)
    dfs(x,y+1,d+1);
    else
    dfs(x+1,1,d+1);

    flip(x,y);
    if(y<4)
    dfs(x,y+1,d);
    else
    dfs(x+1,1,d);
    return ;
}
int main(){
    char temp;
    int i,j;

   for(i=1;i<5;i++)
         for(j=1;j<5;j++)
         {
             cin>>temp;
             if(temp=='b')
                 map[i][j]=true;
         }

    for(step=0;step<=16;step++)
    {
        dfs(1,1,0);
        if(flag)
        break;
    }
    if(flag)
    cout<<step<<endl;
    else
    cout<<"Impossible"<<endl;
    return 0;
}


一个好的解题报告http://www.cnblogs.com/lyy289065406/archive/2011/07/29/2120501.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip
毕设新项目基于python3.7+django+sqlite开发的学生就业管理系统源码+使用说明(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 学生就业管理系统(前端) ## 项目开发环境 - IDE: vscode - node版本: v12.14.1 - npm版本: 6.13.4 - vue版本: @vue/cli 4.1.2 - 操作系统: UOS 20 ## 1.进入项目目录安装依赖 ``` npm install ``` ## 2.命令行执行进入UI界面进行项目管理 ``` vue ui ``` ## 3.编译发布包(请注意编译后存储路径) #### PS:需要将编译后的包复制到后端项目的根目录下并命名为'static' 学生就业管理系统(后端) ## 1.项目开发环境 - IDE: vscode - Django版本: 3.0.3 - Python版本: python3.7.3 - 数据库 : sqlite3(测试专用) - 操作系统 : UOS 20 ## 2.csdn下载本项目并生成/安装依赖 ``` pip freeze > requirements.txt pip install -r requirements.txt ``` ## 3.项目MySQL数据库链接错误 [点击查看解决方法](https://www.cnblogs.com/izbw/p/11279237.html)
pygame.transform.flip() is a method in the Pygame library that is used to flip an image along its axis. This method can be used to create mirror images or to change the orientation of an image. The method takes three arguments: the image to be flipped, a boolean value indicating whether to flip the image horizontally, and a boolean value indicating whether to flip the image vertically. Syntax: ``` pygame.transform.flip(surface, xbool, ybool) ``` - surface: The image to be flipped. - xbool: A boolean value indicating whether to flip the image horizontally (True or False). - ybool: A boolean value indicating whether to flip the image vertically (True or False). Example: ``` import pygame pygame.init() # Set up the display display_width = 640 display_height = 480 game_display = pygame.display.set_mode((display_width, display_height)) # Load the image my_image = pygame.image.load("image.png") # Flip the image horizontally flipped_image = pygame.transform.flip(my_image, True, False) # Display the original and flipped images game_display.blit(my_image, (0, 0)) game_display.blit(flipped_image, (display_width/2, 0)) pygame.display.update() # Quit the game pygame.quit() ``` In the above example, we first load an image using the `pygame.image.load()` method. We then use the `pygame.transform.flip()` method to create a flipped version of the image by passing in `True` as the first argument to indicate that we want to flip the image horizontally. We then display both the original and flipped images using the `blit()` method. Finally, we update the display and quit the game.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值