题目描述:

  有3*3的9个时钟,每个始终有0,1,2,3四种可以循环的状态码,每组数据给我们9个时钟的一种状态码。另外还有9种操作,分别使指定位置的时钟状态码加一,求使得9个时钟状态码全部置于0的最少操作数。

思路:

  可以得知,每种操作数若执行了四次,则等同于不操作,所以每种操作数的次数在0-3之间,另外,题目明确告诉我们,每种状态只有一种答案。4^9,数据规模不大,把9种操作对应的位置存入一个数组,直接爆搜,也不用考虑什么情况。

  后来想了一下,这题应该可以用高斯消元做,效率可以提高很多。

  最后的输出格式多了一个空格,要处理的话比较麻烦,提交竟然AC了。

#include<cstdio>
#include<iostream>
using namespace std; int move[][] = {{},{,,,,,,},{,,,,},{,,,,,,},{,,,,,,,,},{,,,,,,,,,},
{,,,,,,,,,},{,,,,,,,,,},{,,,,,,,,,},{,,,,,,,,,}}; int main()
{
int a[];
for(int i = ;i <= ;i++) cin >> a[i];
int i1,i2,i3,i4,i5,i6,i7,i8,i9;
for(i1 = ;i1 <= ;i1++)
for(i2 = ;i2 <= ;i2++)
for(i3 = ;i3 <= ;i3++)
for(i4 = ;i4 <= ;i4++)
for(i5 = ;i5 <= ;i5++)
for(i6 = ;i6 <= ;i6++)
for(i7 = ;i7 <= ;i7++)
for(i8 = ;i8 <= ;i8++)
for(i9 = ;i9 <= ;i9++)
{
int flag = ;
for(int j = ;j <= ;j++)
{
int sum = a[j];
sum += i1*move[][j]+i2*move[][j]+i3*move[][j]
+i4*move[][j]+i5*move[][j]+i6*move[][j]
+i7*move[][j]+i8*move[][j]+i9*move[][j];
if(sum%)
{
flag = ;
break;
}
}
if(flag) continue; while(i1--) cout << "1 ";
while(i2--) cout << "2 ";
while(i3--) cout << "3 ";
while(i4--) cout << "4 ";
while(i5--) cout << "5 ";
while(i6--) cout << "6 ";
while(i7--) cout << "7 ";
while(i8--) cout << "8 ";
while(i9--) cout << "9 ";
cout << endl;
return ;
}
}

POJ_1166_暴搜的更多相关文章

  1. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  2. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  3. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  4. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  5. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  6. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  7. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

  8. HDU4403(暴搜)

    A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  9. suoi62 网友跳 (暴搜+dp)

    传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...

随机推荐

  1. K8S中的ingress-nginx配置

    编辑在有道云笔记中,链接如下: http://note.youdao.com/noteshare?id=8d9ae3a1643e39714b36b58f7507baa2&sub=61C8C20 ...

  2. uni app canvas 不生效

    canvas 创建canvas绘图上下文. <canvas style="width: 300px; height: 200px;" canvas-id="firs ...

  3. how to render html tag

    使用autoescaping If autoescaping is turned on in the environment, all output will automatically be esc ...

  4. 重拾c++第三天(6):分支语句与逻辑运算符

    1.逻辑运算符 && || ! 2.关系运算符优先级高于逻辑运算符 3.cctype库中好用的判断 4. ?:符号用法: 状态1?结果1:结果2 5.switch用法: switch ...

  5. 线性基 - 寻找异或第K大

    XOR is a kind of bit operator, we define that as follow: for two binary base number A and B, let C=A ...

  6. 《C# 爬虫 破境之道》:第一境 爬虫原理 — 第三节:WebResponse

    第二节中,我们介绍了WebRequest,它可以帮助我们发送一个请求,不过正所谓“来而不往非礼也”,对方收到我们的请求,不给点回复,貌似不太合适(不过,还真有脸皮厚的:P). 接下来,就重点研究一下, ...

  7. Asp.Net Core 已支持 gRPC-Web !!

    grpc-dotnet 项目在 PR #695 完成了 ASP.NET Core 服务与 .NET Core gRPC 客户端的 gRPC-Web 实现. 虽然目前还是实验性项目,但是并不阻碍我们为之 ...

  8. Oracle GoldenGate to Confluent with Kafka Connect

    Confluent is a company founded by the team that built Apache Kafka. It builds a platform around Kafk ...

  9. SycSec成都信息工程大学2019CTF-前五道WEB题writeup

    一.WEB (1)一起来撸猫 flag藏在标签的注释内  <!--这是注释--> (2)你看见过我的菜刀么 eval漏洞 利用蚁剑连接 连接密码就是要post传的参数 连接成功后在网站根目 ...

  10. 如何查看Ubuntu服务器上Django项目的MySQL服务有没有挂?

    如果你在项目内输入:MySQL -uroot -p 接着输入密码之后返回ERROR:1045……如下图 那么这就说明MySQL服务挂了. 需要重新启动一下 重启时在项目目录下输入:sudo servi ...