爆搜就可以过,不过我用了迭代加深。

注意每个操作最多进行4次

#include <cstdio>
#include <cstdlib>
using namespace std; #define MAX_ANS 100 int clock[];
char move[][] = {"ABDE", "ABC", "BCEF", "ADG", "BDEFH", "CFI", "DEGH", "GHI", "EFHI"};
int ans[MAX_ANS], ans_num; void input()
{
for (int i = ; i < ; i++)
scanf("%d", &clock[i]);
} void output()
{
printf("%d", ans[]);
for (int i = ; i < ans_num; i++)
printf(" %d", ans[i]);
putchar('\n');
} bool ok()
{
for (int i = ; i < ; i++)
if (clock[i])
return false;
return true;
} void make(char* move, int value)
{
for (int i = ; move[i]; i++)
{
int index = move[i] - 'A';
clock[index] = (clock[index] + value + ) % ;
}
} void dfs(int step, int limit, int move_index)
{
if (step > limit)
return;
if (ok())
{
output();
exit();
}
for (int i = move_index; i < ; i++)
{
for (int j = ; j < ; j++)
{
make(move[i], );
ans[ans_num++] = i + ;
dfs(step + , limit, i + );
}
ans_num -= ;
make(move[i], -);
}
} int main()
{
input();
for (int i = ; i < ; i++)
{
ans_num = ;
dfs(, i, );
}
return ;
}

poj1166的更多相关文章

  1. poj1166学习中

    #include <iostream> #include <string.h> #include <cstdio> #include <cmath> u ...

  2. poj1166时钟翻转

    #include<stdio.h> #define TABLE_LEN 5 const int table[10][TABLE_LEN]= {{},{1,2,4,5},{1,2,3},{2 ...

  3. POJ1166 The Clocks (爆搜 || 高斯消元)

    总时间限制: 1000ms,内存限制: 65536kB 描述 |-------| |-------| |-------| | | | | | | | |---O | |---O | | O | | | ...

  4. poj分类 很好很有层次感。

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  5. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  6. 【转】ACM训练计划

    [转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...

  7. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  8. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. acm常见算法及例题

    转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题  初期:一.基本算法:     (1)枚举. (poj17 ...

随机推荐

  1. tuple内部方法

    代码: #tuple内部方法 ac=('a','r','6','d','a','b','b','e') print(dir(ac)) print(ac.count('a')) print(ac.ind ...

  2. this的使用

    1.使用this调用本类中的属性 class Person{ private String name; private int age; public Person(String name,int a ...

  3. groovy-语句

    groovy语句类似于java语句,但是在groovy中的分号”;”是可选的.比如: 1 def x = [1, 2, 3] 2 println x 3 def y = 5; def x = y +  ...

  4. pthread_create线程创建的过程剖析

    http://blog.csdn.net/wangyin159/article/details/47082125 在Linux环境下,pthread库提供的pthread_create()API函数, ...

  5. anr产生的原理&如何避免(android)

  6. std::stringstream

    使用 std::stringstream,小心 内存! 适时 清空 缓冲 …… 2007年12月14日 星期五 : stringstream是个好东西,网上有不少文章,讨论如何用它实现各种数据类型的转 ...

  7. tomcat管理页面用户角色、用户名、用户密码的配置

    参考资料:http://www.365mini.com/page/tomcat-manager-user-configuration.htm 编辑tomcat/conf/tomcat-users.xm ...

  8. Matplotlib中文设置

    1.中文设置方法,代码前加入语句 from pylab import mpl mpl.rcParams['font.sans-serif'] = ['SimHei'] 2.例子 # -*- codin ...

  9. C# 获取文件MD5校验码

    using System; using System.IO; using System.Security.Cryptography; using System.Text; public class M ...

  10. JavaScrip操作Cookie

    //生成cookie function addCookie(sName, sValue, day) { var expireDate = new Date(); expireDate.setDate( ...