hdu 1667 IDA*
来源:互联网 发布:windows 10自带备份 编辑:程序博客网 时间:2024/06/05 04:17
第一道IDA*。。。。。。
给链接:点击打开链接
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int num[7][7];int maxdeep;char record[1000];bool check(){int temp = num[2][2];for( int i = 2; i <= 4; i++ ){if( num[2][i] != temp ){return false;}}if( num[3][2] != temp || num[3][4] != temp ){return false;}for( int i = 2; i <= 4; i++ ){if( num[4][i] != temp ){return false;}}return true;}int h(){int cnt[4] = { 0 };cnt[num[2][2]]++;cnt[num[2][3]]++;cnt[num[2][4]]++;cnt[num[3][2]]++;cnt[num[3][4]]++;cnt[num[4][2]]++;cnt[num[4][3]]++;cnt[num[4][4]]++;int ans = 0;for( int i = 1; i <= 3; i++ ){ans = max( ans, cnt[i] );}return 8 - ans;}int rotationA(){int temp = num[0][2];for( int i = 0; i < 6; i++ ){num[i][2] = num[i+1][2];}num[6][2] = temp;return 0;}int rotationB(){int temp = num[0][4];for( int i = 0; i < 6; i++ ){num[i][4] = num[i+1][4];}num[6][4] = temp;return 0;}int rotationC(){int temp = num[2][6];for( int i = 6; i > 0; i-- ){num[2][i] = num[2][i-1];}num[2][0] = temp;return 0;}int rotationD(){int temp = num[4][6];for( int i = 6; i > 0; i-- ){num[4][i] = num[4][i-1];}num[4][0] = temp;return 0;}int rotationE(){int temp = num[6][4];for( int i = 6; i > 0; i-- ){num[i][4] = num[i-1][4];}num[0][4] = temp;return 0;}int rotationF(){int temp = num[6][2];for( int i = 6; i > 0; i-- ){num[i][2] = num[i-1][2];}num[0][2] = temp;return 0;}int rotationG(){int temp = num[4][0];for( int i = 0; i < 6; i++ ){num[4][i] = num[4][i+1];}num[4][6] = temp;return 0;}int rotationH(){int temp = num[2][0];for( int i = 0; i < 6; i++ ){num[2][i] = num[2][i+1];}num[2][6] = temp;return 0;}bool DFS( int deep ){if( deep == maxdeep ){return check();}if( deep + h() > maxdeep ){return false;} rotationA();record[deep] = 'A';if( DFS( deep + 1 ) ){return true;}rotationF();rotationB();record[deep] = 'B';if( DFS( deep + 1 ) ){return true;}rotationE();rotationC();record[deep] = 'C';if( DFS( deep + 1 ) ){return true;}rotationH();rotationD();record[deep] = 'D';if( DFS( deep + 1 ) ){return true;}rotationG();rotationE();record[deep] = 'E';if( DFS( deep + 1 ) ){return true;}rotationB();rotationF();record[deep] = 'F';if( DFS( deep + 1 ) ){return true;}rotationA();rotationG();record[deep] = 'G';if( DFS( deep + 1 ) ){return true;}rotationD();rotationH();record[deep] = 'H';if( DFS( deep + 1 ) ){return true;}rotationC();return false;}int main(){while( cin >> num[0][2] && num[0][2] ){cin >> num[0][4] >> num[1][2] >> num[1][4];for( int i = 0; i < 7; i++ ){cin >> num[2][i];}cin >> num[3][2] >> num[3][4];for( int i = 0; i < 7; i++ ){cin >> num[4][i];}for( int i = 5; i < 7; i++ ){cin >> num[i][2] >> num[i][4];}maxdeep = 0;while( 1 ){if( DFS( 0 ) ){break;}maxdeep++;}if( maxdeep == 0 ){cout << "No moves needed" << endl;}else{for( int i = 0; i < maxdeep; i++ ){cout << record[i];}cout << endl;}cout << num[2][2] << endl;}return 0;}
0 0
- hdu 1667 IDA*
- hdu 1667(IDA*)
- HDU 1667 The Rotation Game IDA*搜索
- HDU-1667 The Rotation Game(IDA*)
- hdu 1667 The Rotation Game(IDA*)
- hdu 1667 The Rotation Game(IDA*)
- hdu 1685 Booksort (IDA*)
- hdu 2234 IDA*
- hdu 1560 IDA*
- hdu 1813 IDA*
- hdu 2918 IDA*
- hdu 3459 IDA*
- 【IDA*】hdu 1560
- hdu 2234(IDA*)
- hdu 1560(IDA*)
- hdu 1813(IDA*)
- hdu 2918(IDA*)
- HDU-1685-Booksort(IDA*)
- Visual C++ ADO数据库编程入门(下)
- 黑马程序员-----Java基础学习多线程
- sql 语句的limit的用法(转载)
- Asp.net网站访问量的统计
- String连接相关
- hdu 1667 IDA*
- 每日任务
- 由浅入深漫谈margin属性
- Android去掉标题栏和全屏
- Java 理论与实践: JDK 5.0 中更灵活、更具可伸缩性的锁定机制
- Java对象对比
- 工欲善其事,必先利其器
- 战略上藐视,战术上重视
- Ubuntu无法打开图片和pdf