总时间限制: 1000ms,内存限制: 65536kB
描述
|-------|    |-------|    |-------|
| | | | | | |
|---O | |---O | | O |
| | | | | |
|-------| |-------| |-------|
A B C |-------| |-------| |-------|
| | | | | |
| O | | O | | O |
| | | | | | | | |
|-------| |-------| |-------|
D E F |-------| |-------| |-------|
| | | | | |
| O | | O---| | O |
| | | | | | | |
|-------| |-------| |-------|
G H I
(Figure )

There are nine clocks in a 3*3 array (figure 1). The goal is to return all the dials to 12 o'clock with as few moves as possible. There are nine different allowed ways to turn the dials on the clocks. Each such way is called a move. Select for each move a number 1 to 9. That number will turn the dials 90' (degrees) clockwise on those clocks which are affected according to figure 2 below.

Move   Affected clocks

          ABDE
ABC
BCEF
ADG
BDEFH
CFI
DEGH
GHI
EFHI
(Figure )

输入

Your program is to read from standard input. Nine numbers give the start positions of the dials. 0=12 o'clock, 1=3 o'clock, 2=6 o'clock, 3=9 o'clock.

输出

Your program is to write to standard output. Output a shortest sorted sequence of moves (numbers), which returns all the dials to 12 o'clock. You are convinced that the answer is unique.

样例输入


样例输出

   

学枚举时候的课程作业,第一次接触到爆搜的魅力,实在是香。不过这题还可以用高斯消元,也是学到了。

爆搜代码

#include <string.h>
#include <stdio.h>
int main()
{
int i, a[], b[], c[]; //多开一位空间,安全,b[i]就是第i种Move,c[i]就是Move之后第i个时钟的状态
for (i = ; i <= ; i++)
scanf("%d", &a[i]); //读入初始状态
//枚举每一种移动方法,每一种可实施0,1,2,3次
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
for (b[] = ; b[] <= ; b[]++)
{
c[] = (a[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[] + b[]) % ;
c[] = (a[] + b[] + b[] + b[]) % ;
if (c[] + c[] + c[] + c[] + c[] + c[] + c[] + c[] + c[] == )
{
for (i = ; i < b[]; i++) printf("1 ");
for (i = ; i < b[]; i++) printf("2 ");
for (i = ; i < b[]; i++) printf("3 ");
for (i = ; i < b[]; i++) printf("4 ");
for (i = ; i < b[]; i++) printf("5 ");
for (i = ; i < b[]; i++) printf("6 ");
for (i = ; i < b[]; i++) printf("7 ");
for (i = ; i < b[]; i++) printf("8 ");
for (i = ; i < b[]; i++) printf("9 ");
printf("\n");
return();
}
}
}

高斯消元做法链接:

https://blog.csdn.net/sf____/article/details/9863927

POJ1166 The Clocks (爆搜 || 高斯消元)的更多相关文章

  1. POJ 1166 The Clocks (爆搜 || 高斯消元)

    题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...

  2. POJ 1166 The Clocks 高斯消元 + exgcd(纯属瞎搞)

    依据题意可构造出方程组.方程组的每一个方程格式均为:C1*x1 + C2*x2 + ...... + C9*x9 = sum + 4*ki; 高斯消元构造上三角矩阵,以最后一个一行为例: C*x9 = ...

  3. luogu P2962 [USACO09NOV]灯Lights 高斯消元

    目录 题目链接 题解 题目链接 luogu P2962 [USACO09NOV]灯Lights 题解 可以折半搜索 map合并 复杂度 2^(n / 2)*logn 高斯消元后得到每个点的翻转状态 爆 ...

  4. [多校2015.02.1006 高斯消元] hdu 5305 Friends

    题意: 给你n个人m条关系 每条关系包括a,b 代表a和b能够是线上朋友也能够是线下朋友 然后保证每一个人的线上朋友数和线下朋友数相等 问你有多少种组成方法 思路: 官方题解是爆搜+剪枝,然而并不会写 ...

  5. BZOJ1770:[USACO]lights 燈(高斯消元,DFS)

    Description 貝希和她的閨密們在她們的牛棚中玩遊戲.但是天不從人願,突然,牛棚的電源跳閘了,所有的燈都被關閉了.貝希是一個很膽小的女生,在伸手不見拇指的無盡的黑暗中,她感到驚恐,痛苦與絕望. ...

  6. [Usaco2009 Nov]lights(高斯消元)

    luogu 点灯游戏应该很多人都在小时候頽过吧 反正我直到现在也不会 很明显一个灯最多只需要点一次 然后高斯消元 解完肯定剩自由元(就是那些全是0的行) 然后这些都爆搜 由于剩下的自由元不会太多 所以 ...

  7. POJ_1222_高斯消元

    题目描述: 每组数据给出一个5*6的0 1矩阵,每次操作可以把某个位置及其四周的位置0 1置换,要求输出操作位置的矩阵. 思路: 每个位置操作2次则等于没有操作,所以每个位置有操作和不操作两种选择,爆 ...

  8. 高斯消元 分析 && 模板 (转载)

    转载自:http://hi.baidu.com/czyuan_acm/item/dce4e6f8a8c45f13d7ff8cda czyuan 先上模板: /* 用于求整数解得方程组. */ #inc ...

  9. BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )

    高斯消元解xor方程组...暴搜自由元+最优性剪枝 -------------------------------------------------------------------------- ...

随机推荐

  1. Thinkphp3.2下导入所需的类库 同java的Import 本函数有缓存功能

    * 导入所需的类库 同java的Import 本函数有缓存功能 * @param string $class 类库命名空间字符串 * @param string $baseUrl 起始路径 * @pa ...

  2. 【Selenium-WebDriver实战篇】基于java的selenium之验证码识别内容

    ==================================================================================================== ...

  3. [转]windows10下安装与激活rational rose 2003

    Rational Rose2003安装+激活教程(Win10)(另附安装包+激活软件) 原文链接:https://blog.csdn.net/qq_38388811/article/details/8 ...

  4. LeetCode 1004. Max Consecutive Ones III

    原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-iii/ 题目: Given an array A of 0s and 1s, w ...

  5. rustup 使用

    rustup 可以帮助我们安装不同版本的rust 编程需要的工具连,同时可以方便的进行不同版本 之间的切换,类似nodejs 的nvm,n, ruby 的 rvm python 的 venv ... ...

  6. 56、Spark Streaming: transform以及实时黑名单过滤案例实战

    一.transform以及实时黑名单过滤案例实战 1.概述 transform操作,应用在DStream上时,可以用于执行任意的RDD到RDD的转换操作.它可以用于实现,DStream API中所没有 ...

  7. CMD下文件操作

    CMD下常用文件操作指令 1.输入盘符 如C: 然后回车,相当于进了C盘(c盘一般进的是桌面目录) 2.输入 cd 目录名 然后回车(目录名是c盘中的一级目录名,也可为c盘中的目录路径).如cd mm ...

  8. Brexit Gym - 101490C

    题目链接:Brexit vector的使用(vector存边),巧用queue,相当于Bfs /* */ # include <iostream> # include <cstdio ...

  9. struct tcphdr

    包含在/usr/src/linux/include/linux/tcp.h struct tcphdr { __be16 source; __be16 dest; __be32 seq; __be32 ...

  10. js中forEach,for in,for of循环的用法详解

    一.一般的遍历数组的方法: var array = [1,2,3,4,5,6,7]; for (var i = 0; i < array.length; i) { console.log(i,a ...