首页 > 其他分享 > UVA1343 旋转游戏 The Rotation Game

UVA1343 旋转游戏 The Rotation Game

时间:2022-12-12 21:59:45浏览次数:46  
标签:return leftsandrights int UVA1343 cz Game dfs str Rotation

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;
const int read [25][2] =
{
	{ 0 , 0 } , 
							{ 1 , 3 } , 			{ 1 , 5 } , 
							{ 2 , 3 } , 			{ 2 , 5 } , 
	{ 3 , 1 } , { 3 , 2 } , { 3 , 3 } , { 3 , 4 } , { 3 , 5 } , { 3 , 6 } , { 3 , 7 } , 
							{ 4 , 3 } , 			{ 4 , 5 } ,
	{ 5 , 1 } , { 5 , 2 } , { 5 , 3 } , { 5 , 4 } , { 5 , 5 } , { 5 , 6 } , { 5 , 7 } , 
							{ 6 , 3 } , 			{ 6 , 5 } , 
							{ 7 , 3 } , 			{ 7 , 5 } , 
};
int md ;
int x [ 11 ] [ 11 ] ;
namespace cz{ 
	void leftsandrights ( int q , int type ) {
		if ( type == 1 ) {//lefts
			int s = x [ q ] [ 1 ] ;
			for ( int i = 1 ; i < 7 ; i ++ ) 
				x [ q ] [ i ] = x [ q ] [ i + 1 ] ;
			x [ q ] [ 7 ] = s ;
		}
		if ( type == 2 ) {//rights
			int s = x [ q ] [ 7 ] ;
			for ( int i = 7 ; i > 1 ; i -- ) 
				x [ q ] [ i ] = x [ q ] [ i - 1 ] ;
			x [ q ] [ 1 ] = s ; 
		}
	}
	void upsanddowns ( int q , int type ) {
		if ( type == 1 ) {//ups
			int s = x [ 1 ] [ q ] ;
			for ( int i = 1 ; i < 7 ; i ++ ) 
				x [ i ] [ q ] = x [ i + 1 ] [ q ] ;
			x [ 7 ] [ q ] = s ; 
		}
		if ( type == 2 ) {//downs
			int s = x [ 7 ] [ q ] ;
			for ( int i = 7 ; i > 1 ; i -- ) 
				x [ i ] [ q ] = x [ i - 1 ] [ q ] ;
			x [ 1 ] [ q ] = s ; 
		}
	}
 }
string str;
int checks ( ) {
	int sum [ 4 ] = { 0 , 0 , 0 , 0 } ;
	for ( int i = 3 ; i <= 5 ; i ++ )
		for ( int j = 3 ; j <= 5 ; j ++ )
			sum [ x [ i ] [ j ] ] ++ ;
	return 8 - max ( sum [ 1 ] , max ( sum [ 2 ] , sum [ 3 ] ) ) ;
}
void print ( ) {
	for ( int i = 1 ; i <= 7 ; i ++ , cout << '\n' ) {
		for ( int j = 1 ; j <= 7 ; j ++ ) cout << x [ i ] [ j ] << " " ;
	}
	return ;
}

bool dfs ( int now , char pre ) {
	int number = checks ( ) ;
	if ( number == 0 ) return true ;
	if ( number + now > md ) return false ; 
	if ( pre != 'F' ) {
		cz :: upsanddowns ( 3 , 1 ) ;
		if ( dfs ( now + 1 , 'A' ) ) { str = str + "A" ; return true ; }
		cz :: upsanddowns ( 3 , 2 ) ;
	}
	if ( pre != 'E' ) {
		cz :: upsanddowns ( 5 , 1 ) ;
		if ( dfs ( now + 1 , 'B' ) ) { str = str + "B" ; return true ; }
		cz :: upsanddowns ( 5 , 2 ) ;
	}
	if ( pre != 'H' ) {
		cz :: leftsandrights ( 3 , 2 ) ;
		if ( dfs ( now + 1 , 'C' ) ) { str = str + "C" ; return true ; }
		cz :: leftsandrights ( 3 , 1 ) ;
	}
	if ( pre != 'G' ) {
		cz :: leftsandrights ( 5 , 2 ) ;
		if ( dfs ( now + 1 , 'D' ) ) { str = str + "D" ; return true ; }
		cz :: leftsandrights ( 5 , 1 ) ; 
	}
	if ( pre != 'B' ) {
		cz :: upsanddowns ( 5 , 2 ) ;
		if ( dfs ( now + 1 , 'E' ) ) { str = str + "E" ; return true ; }
		cz :: upsanddowns ( 5 , 1 ) ; 
	}
	if ( pre != 'A' ) {
		cz :: upsanddowns ( 3 , 2 ) ;
		if ( dfs ( now + 1 , 'F' ) ) { str = str + "F" ; return true ; }
		cz :: upsanddowns ( 3 , 1 ) ; 
	}
	if ( pre != 'D' ) {
		cz :: leftsandrights ( 5 , 1 ) ;
		if ( dfs ( now + 1 , 'G' ) ) { str = str + "G" ; return true ; }
		cz :: leftsandrights ( 5 , 2 ) ; 
	}
	if ( pre != 'C' ) {
		cz :: leftsandrights ( 3 , 1 ) ;
		if ( dfs ( now + 1 , 'H' ) ) { str = str + "H" ; return true ; }
		cz :: leftsandrights ( 3 , 2 ) ;
	}
	return false ;
}
int main ( ) {
	while ( 1 ) 
	{
        str = "";
		md = 0 ;
		cin >> x [ read [ 1 ] [ 0 ] ] [ read [ 1 ] [ 1 ] ] ;
		if ( x [ read [ 1 ] [ 0 ] ] [ read [ 1 ] [ 1 ] ] == 0 ) return 0 ;
		for ( int i = 2 ; i <= 24 ; i ++ )
			cin >> x [ read [ i ] [ 0 ] ] [ read [ i ] [ 1 ] ] ;
		for ( md = 0 ; ; md ++ ) 
		if ( dfs ( 1 , '1' ) )
		{
            if ( md == 0 )
            	cout << "No moves needed\n";
            else
            {
            	reverse ( str . begin () , str . end ( ) ) ; 
           		cout << str << endl;
            }
            cout << x [ 3 ] [ 3 ] << endl ;
            break;
		}
	}
	return 0 ;
}

标签:return,leftsandrights,int,UVA1343,cz,Game,dfs,str,Rotation
From: https://www.cnblogs.com/dadidididi/p/16977196.html

相关文章

  • [dp 记录]agc016F Game on DAG
    博弈论好题,做完感觉加深了对SG函数的理解!题意:给定一张DAG,问该DAG的\(2^m\)张导出子图中有多少张满足\(SG[1]=SG[2]\)注:此为转换后题意\(n\leq15\)考虑推......
  • Game 2048
    Thegame2048isapuzzlegameplayedona4x4grid.Thegoalofthegameistoslidethetilesonthegridtocombinethemandcreateatilewiththenumber2......
  • UE Gameplay Learning Record
    UEGameplayLearningType:#LearnTags:#UnrealEngine#GameplayStatus:#DoingTime:2022-12-1011:20WrittenBy:yocichenSummary将我自己学习UE......
  • 基于Python pygame简易版斗兽棋小游戏源代码
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......
  • 偶遇 Trojan.PSW.Win32.OnlineGames.xym,Trojan.Win32.Agent.vvk等
    偶遇Trojan.PSW.Win32.OnlineGames.xym,Trojan.Win32.Agent.vvk等endurer原创2007-09-19 第1版刚才一位网友说他的电脑最近启动一个程序所需时间比较长。让偶通过QQ远程......
  • 抓获Backdoor.Gpigeon.voo和Trojan.PSW.OnlineGames.xd等盗号木马
    endurer原创2007-05-08第1版一位朋友,说他的电脑最近运行很慢,让偶帮忙检修。下载pe_xscan扫描log并分析,发现如下可疑项:/---pe_xscan07-04-12byPurpleEndurer2007-5......
  • 一位网友的电脑中了Trojan.PSW.OnlineGames.amc
    endurer原创2007-04-24第1版昨天,一位网友的电脑中了Trojan.PSW.OnlineGames.amc,虽然被瑞星查杀了,但他不太放心,让偶通过QQ远程协助帮忙检查。一看,瑞星实时监控居然没有开,不......
  • UVALive 2038 Strategic game--树形dp
    原题链接:​​http://vjudge.net/problem/UVALive-2038​​题意:一棵树,n个点,0为根,求最少的点可以覆盖所有边。分析:dp[u][0]表示u点不选;dp[u][1]表示该点选择。#defin......
  • hdu3622 Bomb Game--2-sat & 二分
    原题链接:​​http://acm.hdu.edu.cn/showproblem.php?pid=3622​​题意:一个二维坐标系,n行数据,每行两个坐标算作一组,从n组跳出n点,画圆,半径一样,要求不能相交,可以相切,求最大半......
  • Python3+pygame实现飞机大战游戏(免费完整项目)
    版权声明:原创不易,本文禁止抄袭、转载,侵权必究! 一、开发环境开发环境:Windows10   Python3.6.4第三方库:Pygame1.9.6IDE    :PyCharm/SublimeText ......