当前位置:网站首页>hdu 5077 NAND(暴力打表)
hdu 5077 NAND(暴力打表)
2022-07-06 15:10:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
题目大意:Xiaoqiang要写一个编码程序,然后依据x1,x2,x3的值构造出8个字符。如今给定要求生成的8个字符。问
说Xiaoqiang最少要写多少行代码。代码内容仅仅能为NAND操作和return操作,操作的变量能够是常数。
解题思路:输入总共就256中情况,所以暴力剪枝打表,打表的代码手贱给删了。。。所以就将一下思路。开一个s数组
表示变量,然后相应每一层每次两个变量进行NAND操作。
大致三个剪枝,dfs时候,变量出现同样就跳过。8个字符能够直接依据数的位运算计算;单前层出现同样的跳过。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int ans[300] = {1, 5, 6, 3, 6, 3, 7, 4, 7, 8, 4, 5, 4, 5, 4, 1, 6, 3, 7, 4, 7, 4, 9, 7, 8, 8, 7, 5, 7, 5, 7, 4, 7, 8, 4, 5, 8, 8, 7, 5, 8, 9, 5, 6, 8, 8, 5, 5, 4, 5, 4, 1, 7, 5, 7, 4, 8, 8, 5, 5, 5, 7, 6, 4, 7, 8, 8, 8, 4, 5, 7, 5, 8, 9, 8, 8, 5, 6, 5, 5, 4, 5, 7, 5, 4, 1, 7, 4, 8, 8, 5, 7, 5, 5, 6, 4, 8, 9, 8, 8, 8, 8, 5, 7, 11, 9, 8, 9, 8, 9, 8, 8, 5, 6, 5, 5, 5, 5, 6, 4, 8, 9, 8, 8, 8, 8, 8, 7, 8, 9, 9, 9, 9, 9, 10, 9, 5, 7, 6, 6, 6, 6, 7, 6, 9, 9, 10, 9, 10, 9, 10, 10, 7, 6, 7, 7, 7, 7, 9, 7, 5, 7, 6, 6, 7, 6, 7, 7, 5, 6, 2, 3, 6, 6, 4, 3, 6, 6, 7, 6, 7, 7, 9, 7, 6, 6, 4, 3, 7, 7, 7, 6, 5, 7, 7, 6, 6, 6, 7, 7, 5, 6, 6, 6, 2, 3, 4, 3, 6, 6, 7, 7, 7, 6, 9, 7, 6, 6, 7, 7, 4, 3, 7, 6, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, 5, 6, 5, 6, 2, 5, 2, 3, 4, 3, 4, 3, 7, 6, 5, 6, 2, 5, 2, 5, 4, 1};
int main () {
int cas;
char p[10];
scanf("%d", &cas);
while (cas--) {
scanf("%s", p);
int ret = 0;
for (int i = 0; i < 8; i++)
ret = ret * 2 + p[i] - '0';
printf("%d\n", ans[ret]);
}
return 0;
}版权声明:本文博主原创文章。博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116988.html原文链接:https://javaforall.cn
边栏推荐
- void关键字
- 柔性数组到底如何使用呢?
- UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
- 自制J-Flash烧录工具——Qt调用jlinkARM.dll方式
- 0 basic learning C language - interrupt
- 图像的spatial domain 和 frequency domain 图像压缩
- Adavit -- dynamic network with adaptive selection of computing structure
- Aardio - 不声明直接传float数值的方法
- 新手程序员该不该背代码?
- Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
猜你喜欢

基于 QEMUv8 搭建 OP-TEE 开发环境

【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真

labelimg的安装与使用

剑指offer刷题记录1

软考高级(信息系统项目管理师)高频考点:项目质量管理

第3章:类的加载过程(类的生命周期)详解

Aardio - 通过变量名将变量值整合到一串文本中

2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9

剪映+json解析将视频中的声音转换成文本

Mise en place d'un environnement de développement OP - tee basé sur qemuv8
随机推荐
2022-07-05 使用tpcc对stonedb进行子查询测试
Gd32f4xx serial port receive interrupt and idle interrupt configuration
【无标题】
雅思口语的具体步骤和时间安排是什么样的?
硬件開發筆記(十): 硬件開發基本流程,制作一個USB轉RS232的模塊(九):創建CH340G/MAX232封裝庫sop-16並關聯原理圖元器件
Pit encountered by handwritten ABA
[IELTS speaking] Anna's oral learning record part1
剑指offer刷题记录1
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
three.js绚烂的气泡效果
0 basic learning C language - digital tube
云原生技术--- 容器知识点
做接口测试都测什么?有哪些通用测试点?
中国固态氧化物燃料电池技术进展与发展前景报告(2022版)
Learn the principle of database kernel from Oracle log parsing
自定义 swap 函数
What are the specific steps and schedule of IELTS speaking?
2022-07-05 stonedb的子查询处理解析耗时分析
Assembly and Interface Technology Experiment 6 - ADDA conversion experiment, AD acquisition system in interrupt mode
如何用程序确认当前系统的存储模式?