当前位置:网站首页>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
边栏推荐
- [IELTS speaking] Anna's oral learning record part1
- qt quick项目offscreen模式下崩溃的问题处理
- 基于 QEMUv8 搭建 OP-TEE 开发环境
- Memorabilia of domestic database in June 2022 - ink Sky Wheel
- 树的先序中序后序遍历
- PVL EDI project case
- C# 三种方式实现Socket数据接收
- 2021 geometry deep learning master Michael Bronstein long article analysis
- 中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
- [sdx62] wcn685x will bdwlan Bin and bdwlan Txt mutual conversion operation method
猜你喜欢
Config:invalid signature solution and troubleshooting details
Advantages of link local address in IPv6
Pit encountered by handwritten ABA
Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
uniapp滑动到一定的高度后固定某个元素到顶部效果demo(整理)
Management background --4, delete classification
Mysql database basic operations DML
Should novice programmers memorize code?
(十八)LCD1602实验
MySQL----初识MySQL
随机推荐
Leetcode exercise - Sword finger offer 26 Substructure of tree
Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
[linear algebra] determinant of order 1.3 n
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
【编译原理】做了一半的LR(0)分析器
Senior soft test (Information System Project Manager) high frequency test site: project quality management
Sword finger offer question brushing record 1
0 basic learning C language - digital tube
void关键字
The nearest common ancestor of binary (search) tree ●●
GD32F4XX串口接收中断和闲时中断配置
【踩坑合辑】Attempting to deserialize object on CUDA device+buff/cache占用过高+pad_sequence
3DMAX assign face map
Export MySQL table data in pure mode
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
中国VOCs催化剂行业研究与投资战略报告(2022版)
NPDP certification | how do product managers communicate across functions / teams?
extern关键字
Web APIs DOM 时间对象
二叉(搜索)树的最近公共祖先 ●●