Tautology---poj3295(枚举判断是否为永真式)
2024-09-24 04:13:05
题目链接:http://poj.org/problem?id=3295
题意:判断是否是永真式,其中 p q r s t 表示逻辑变量其值为0或者1;
枚举所有逻辑变量的值,然后判断是否出现false
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stack> using namespace std; #define met(a, b) memset(a, b, sizeof(a))
#define N 111 typedef long long LL; int p, q, r, s, t, len;
char str[N]; bool Judge()
{
stack<int> Sta;
for(int i=len-; i>=; i--)
{
int x1, x2;
if(str[i] == 'p')Sta.push(p);
else if(str[i] == 'q')Sta.push(q);
else if(str[i] == 'r')Sta.push(r);
else if(str[i] == 's')Sta.push(s);
else if(str[i] == 't')Sta.push(t);
else if(str[i] == 'K')
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push(x1&&x2);
}
else if(str[i] == 'A')
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push(x1||x2);
}
else if(str[i] == 'N')
{
x1 = Sta.top();Sta.pop();
Sta.push(!x1);
}
else if(str[i] == 'C')
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push( !(x1&&!x2) );
}
else
{
x1 = Sta.top();Sta.pop();
x2 = Sta.top();Sta.pop();
Sta.push( x1==x2 );
}
}
return Sta.top()==;
} bool solve()
{
len = strlen(str); for(p=; p<; p++)
for(q=; q<; q++)
for(r=; r<; r++)
for(s=; s<; s++)
for(t=; t<; t++)
if(!Judge())
return false;
return true;
} int main()
{
while(scanf("%s", str), strcmp(str, ""))
{
if(solve())puts("tautology");
else puts("not");
}
return ;
}
最新文章
- MySQL5.6 PERFORMANCE_SCHEMA 说明
- 图像预处理第9步:存为.bmp文件
- spider_text
- Java Servlet(八):EL自定义函数
- jQueryMobile控件之页面切换
- Java list的用法排序及遍历
- Windows 多线程知识点汇总
- JDBC中的批量插入和乱码解决
- 终极解决方案:windows10开机黑屏,死机
- NOI2003 文本编辑器
- Swift 2.0 字符串学习笔记(建议掌握OC字符串知识的翻阅)
- .NetCore之下载文件
- Android面试题总结
- .NET Core微服务之基于MassTransit实现数据最终一致性(Part 2)
- shiro(四)项目开发中的配置、
- Redmine简易安装与系统优化
- Android获取虚拟软键盘高度
- Pychram 在model中修改class属性值后更新到Navicat Premium中
- Python-垃圾回收机制
- 关于servelet入门介绍
热门文章
- vux ajax请求 及 跨域
- 使用 requests 维持会话
- C#调用DLL报“试图加载格式不正确的程序”
- erlang安装
- iOS - UITableViewStylePlain与UITableViewStyleGroup样式的对比
- free -m 下的含义
- 【.NetCore学习】ASP.NET Core EF Core2.0 DB First现有数据库自动生成实体Context
- android checkbox样式
- 深入理解 Neutron -- OpenStack 网络实现(1):GRE 模式
- 【SpringCloud微服务实战学习系列】配置详解