poj1166
爆搜就可以过,不过我用了迭代加深。
注意每个操作最多进行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的更多相关文章
- poj1166学习中
#include <iostream> #include <string.h> #include <cstdio> #include <cmath> u ...
- poj1166时钟翻转
#include<stdio.h> #define TABLE_LEN 5 const int table[10][TABLE_LEN]= {{},{1,2,4,5},{1,2,3},{2 ...
- POJ1166 The Clocks (爆搜 || 高斯消元)
总时间限制: 1000ms,内存限制: 65536kB 描述 |-------| |-------| |-------| | | | | | | | |---O | |---O | | O | | | ...
- poj分类 很好很有层次感。
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 【转】POJ题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- 【转】ACM训练计划
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- acm常见算法及例题
转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法: (1)枚举. (poj17 ...
随机推荐
- Java-小数点控制
package 运算及类型转换类; import java.text.DecimalFormat; public class 控制小数点类 { public static double decimal ...
- 【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A In an open credit system, the ...
- BZOJ-1050 旅行comf 并查集+乱搞
好久以前codevs上做过的,拿着改了改.. 1050: [HAOI2006]旅行comf Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2194 S ...
- JSON后端页面解析
json-lib 请求: http://localhost:8080/MyWeb/pay?cmd=getUrl¶m={"OrderId":"sddd111 ...
- JAVA中的数组是对象吗?
public class Main{ public static void main(String[] args) { int a[]={1,9}; //Object obj=new int[10]; ...
- The Longest Increasing Subsequence (LIS)
传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...
- linux下的三种解压文件的命令?
那要看你的压缩文件使用哪种压缩方式:gzip,压缩文件名:zip或gz,解压命令:unzipbzip2,压缩文件名:bz,解压命令:bzip2 -d上面两个是最常用的压缩方式,一般在linux下可以通 ...
- c++ 类型安全
类型安全很大程度上可以等价于内存安全,类型安全的代码不会试图访问自己没被授权的内存区域.“类型安全”常被用来形容编程语言,其根据在于该门编程语言是否提供保障类型安全的机制:有的时候也用“类型安全”形容 ...
- Python socket编程之六:多窗口的应用
import struct import sqlalchemy import pandas import matplotlib.pyplot as Plot from matplotlib.finan ...
- WINDOWS渗透与提权总结(1)
旁站路径问题: 1.读网站配置. 2.用以下VBS: 01 On Error Resume Next 02 03 If (LCase(Right(WScript.Fullname, 11)) = ...