Tautology

思路很简单,对于p、q、r、s、t暴力枚举是0还是1,判断即可。判断时像写表达式求值那样用栈。为了方便可以从后往前,因为最后一个肯定不是运算。那几个奇奇怪怪的函数可以找规律然后转为位运算,简洁又快。

#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
const int MAXN=105;
char a[MAXN];
int n,p,q,r,s,t;
bool ans;
bool isc(char c) {
return c=='p'||c=='q'||c=='r'||c=='s'||c=='t';
}
void push(char c,stack<int>&st) {
if(c=='p')st.push(p);
if(c=='q')st.push(q);
if(c=='r')st.push(r);
if(c=='s')st.push(s);
if(c=='t')st.push(t);
}
int K(int a,int b) {
return a&b;
}
int A(int a,int b) {
return a|b;
}
int N(int a) {
return !a;
}
int C(int a,int b) {
return (!a)|b;
}
int E(int a,int b) {
return !(a^b);
}
void calc(char c,stack<int>&st) {
if(c=='K') {
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(K(a,b));
}
if(c=='A'){
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(A(a,b));
}
if(c=='N'){
int a;
a=st.top(),st.pop();
st.push(N(a));
}
if(c=='C'){
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(C(a,b));
}
if(c=='E'){
int a,b;
b=st.top(),st.pop();
a=st.top(),st.pop();
st.push(E(a,b));
}
}
int main() {
while(scanf("%s",a+1)!=EOF)
{
if(!strcmp(a+1,"0"))return 0;
n=strlen(a+1);
ans=true;
for(p=0; p<=1; ++p) {
for(q=0; q<=1; ++q) {
for(r=0; r<=1; ++r) {
for(s=0; s<=1; ++s) {
for(t=0; t<=1; ++t) {
stack<int>st;
for(int i=n; i>=1; --i) {
if(isc(a[i]))push(a[i],st);
else calc(a[i],st);
}
if(!st.top())
{
ans=false;
goto end;
}
}
}
}
}
}
end:{ans?puts("tautology"):puts("not");}
}
}

POJ3295 Tautology重言式的更多相关文章

  1. [POJ3295]Tautology

    [POJ3295]Tautology 试题描述 WFF 'N PROOF is a logic game played with dice. Each die has six faces repres ...

  2. POJ-3295 Tautology (构造)

    https://vjudge.net/problem/POJ-3295 题意 有五种运算符和五个参数,现在给你一个不超过100字符的算式,问最后结果是否恒为1? 分析 首先明确各运算符的意义,K(&a ...

  3. poj3295 Tautology —— 构造法

    题目链接:http://poj.org/problem?id=3295 题意: 输入由p.q.r.s.t.K.A.N.C.E共10个字母组成的逻辑表达式, 其中p.q.r.s.t的值为1(true)或 ...

  4. POJ3295——Tautology

    Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...

  5. POJ3295 Tautology(枚举)

    题目链接. 分析: 最多有五个变量,所以枚举所有的真假值,从后向前借助于栈验证是否为永真式. #include <iostream> #include <cstring> #i ...

  6. poj3295 Tautology , 计算表达式的值

    给你一个表达式,其包括一些0,1变量和一些逻辑运算法,让你推断其是否为永真式. 计算表达式的经常使用两种方法:1.递归: 2.利用栈. code(递归实现) #include <cstdio&g ...

  7. POJ3295 Tautology(栈+枚举)

    Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some ...

  8. ACM学习历程——POJ3295 Tautology(搜索,二叉树)

    Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some ...

  9. POJ3295 Tautology 解题报告

    直接上分析: 首先 弄清各种大写字母的操作的实质 K 明显 是 and   & A 是 or      | N 是 not   ! C  由表格注意到 当 w<=x 时 值为1 E  当 ...

随机推荐

  1. redis 高性能的原因

    1. redis 数据存储在内存中: 2. redis 是单线程: 3. redis 多路复用: 指令先放到队列里 4.redis 使用resp 协议

  2. 在这之后的两天又出现了w3wp进程找不到的情况了

    在这之后的两天又出现了w3wp进程找不到的情况了,我做了什么操作呢?无非就是vs中给一个过程附加删除了了一些dll,然后不停的重新生成解决方案,生成成功后,要调试,发现进程又没了. 实验了上面的方法, ...

  3. Vue - 动态绑定class

    <div :class="{active:item.index==1}" >  </div>

  4. 「Luogu P2468 [SDOI2010]粟粟的书架」

    这道题分为两个部分 Part1 前置芝士 前缀和(后缀和,二维前缀和):可以预处理一下数据. 二分查找:可以在较短的时间内找出答案. 具体做法 可以发现\(R,C\)不大,只有\(200\),于是可以 ...

  5. 常见Http状态码大全详解

    HTTP状态码的分类 HTTP状态码由三个十进制数字组成,第一个十进制数字定义了状态码的类型,后两个数字没有分类的作用.HTTP状态码共分为5种类型: 具体如下: 状态码 内容 详细内容 信息告知 - ...

  6. 由Nginx反向代理引出的JCaptcha验证码验证失败的问题

    搜索关键字: 1)Windows本地开发正常,部署到Linux远程服务器上JCaptcha验证失败 2)Linux远程服务器上JCpatcha验证失败 3)Nginx反向代理后JCaptcha验证失败 ...

  7. Prometheus 学习目录

    Prometheus 介绍 Prometheus 安装 https://www.bookstack.cn/read/prometheus-book/quickstart-why-monitor.md ...

  8. 初识Prometheus

    安装Prometheus Server Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖.用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prom ...

  9. CentOS配置源、wget、ifconfig基础环境

    执行命令: curl http://10.200.0.14:8000/portal.cgi -X POST -d 'username=lishuai&password=test@cetc38& ...

  10. java学习-初级入门-面向对象⑥-类与对象-静态static

    这次我们来学习静态(static) 知识点 1.静态方法只能调用静态变量 2.静态变量属于整个Class,会随着发生变化. 案例:定义一个自动增长的学生类. 题目要求: 定义一个学生类,除了姓名.性别 ...