当前位置:网站首页>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
边栏推荐
- 机试刷题1
- LeetCode 练习——剑指 Offer 26. 树的子结构
- 第3章:类的加载过程(类的生命周期)详解
- 中国固态氧化物燃料电池技术进展与发展前景报告(2022版)
- Build op-tee development environment based on qemuv8
- Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
- UDP编程
- [linear algebra] determinant of order 1.3 n
- Clip +json parsing converts the sound in the video into text
- 每日一题:力扣:225:用队列实现栈
猜你喜欢
0 basic learning C language - interrupt
二叉(搜索)树的最近公共祖先 ●●
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
【LeetCode】19、 删除链表的倒数第 N 个结点
ResNet-RS:谷歌领衔调优ResNet,性能全面超越EfficientNet系列 | 2021 arxiv
pytorch_ Yolox pruning [with code]
Senior soft test (Information System Project Manager) high frequency test site: project quality management
Aardio - 封装库时批量处理属性与回调函数的方法
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
剑指offer刷题记录1
随机推荐
[sdx62] wcn685x will bdwlan Bin and bdwlan Txt mutual conversion operation method
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
Advantages of link local address in IPv6
Notes de développement du matériel (10): flux de base du développement du matériel, fabrication d'un module USB à RS232 (9): création de la Bibliothèque d'emballage ch340g / max232 SOP - 16 et Associa
剪映+json解析将视频中的声音转换成文本
pytorch_YOLOX剪枝【附代码】
Leetcode question brushing (XI) -- sequential questions brushing 51 to 55
[线性代数] 1.3 n阶行列式
NPDP certification | how do product managers communicate across functions / teams?
2021 geometry deep learning master Michael Bronstein long article analysis
Management background --4, delete classification
Assembly and Interface Technology Experiment 6 - ADDA conversion experiment, AD acquisition system in interrupt mode
中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
What are the specific steps and schedule of IELTS speaking?
[leetcode] 19. Delete the penultimate node of the linked list
二叉(搜索)树的最近公共祖先 ●●
volatile关键字
CocosCreator+TypeScripts自己写一个对象池
ThreadLocal详解
如何用程序确认当前系统的存储模式?