POJ 3295 Tautology
来源:互联网 发布:seo by yoast 编辑:程序博客网 时间:2024/06/02 05:48
http://poj.org/problem?id=3295
题目大意:
数学题 判断表达式是否为永真式
p,q,r,s,t --- 变量
K --- 且
A --- 或
N --- 非
C --- 蕴含
E --- 等价
分析:
永真式 即对所有赋值情况 表达式都为真 枚举变量所有赋值 共 25 种情况 表达式真值的计算类似与前缀表达式
AC代码:
#include <stdio.h>#include <string.h>#include <stack>#include <math.h>using namespace std;char str[500];int p,q,r,s,t;int ans(){stack<char> S1;stack<int> S2; for (int i=0;i<strlen(str);i++){S1.push(str[i]);}while (!S1.empty()){char temp=S1.top();S1.pop();if(temp=='p'){S2.push(p);}else if(temp=='q'){S2.push(q);}else if(temp=='r'){S2.push(r);}else if(temp=='s'){S2.push(s);}else if(temp=='t'){S2.push(t);}else if(temp=='N'){int a=S2.top();S2.pop();S2.push(!a);}else if(temp=='A'){int a=S2.top();S2.pop();int b=S2.top();S2.pop();S2.push(a||b);}else if(temp=='K'){int a=S2.top();S2.pop();int b=S2.top();S2.pop();S2.push(a&&b);}else if(temp=='E'){int a=S2.top();S2.pop();int b=S2.top();S2.pop();S2.push(!(a^b));}else if(temp=='C'){int a=S2.top();S2.pop();int b=S2.top();S2.pop();if(b==1&&a==0){S2.push(0);}elseS2.push(1);}}return S2.top();}int oper(){for (int i=0;i<=pow(2,5);i++){// 所有情况 int x=i;p=x%2;x/=2;q=x%2;x/=2;r=x%2;x/=2;s=x%2;x/=2;t=x%2;if(ans()==0)return 0;}return 1;}int main (){while (scanf ("%s",str)){if(str[0]=='0')break;if(oper())printf ("tautology\n");elseprintf ("not\n");}return 0; }
阅读全文
0 0
- POJ 3295 Tautology 模拟
- POJ-3295-Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology(模拟)
- poj 3295 Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- poj 3295 Tautology
- poj-3295 Tautology
- POJ 3295 -Tautology
- POJ 3295 Tautology
- POJ:题号 3295------tautology
- Poj 3295 Tautology
- Tautology POJ 3295
- POJ 3295 Tautology
- poj 3295 Tautology
- AK-47 制造商 Kalashnikov 已成功研发 AI 武器 以 AK-47 闻名世界的俄罗斯军火商 Kalashnikov 近日宣布,其已成功研发全自动武器模块,能够利用人工智能技术识别目
- Educational Codeforces Round 25 D Suitable Replacement 贪心
- 快速排序
- java基础之运算符
- Myeclipse 的hadoop环境搭建
- POJ 3295 Tautology
- leetcode6
- java读取resource/通过文件名获取文件类型
- C++ map遍历
- Ubuntu中MySQL安装配置
- java基础之类
- CimatronE9.0 汉化免费版
- 二分法查找
- CTreeCtrl基本使用