http://poj.org/problem?id=3295

题意:

判断表达式是否为永真式。

思路:

把每种情况都枚举一下。

 #include<iostream>
#include<string>
#include<cstring>
using namespace std; const int MAXN = ; int sta[MAXN];
char str[MAXN];
int p, q, r, s, t; void judge()
{
int top = ;
int len = strlen(str);
for (int i = len - ; i >= ; i--)
{
if (str[i] == 'p') sta[top++] = p;
else if (str[i] == 'q') sta[top++] = q;
else if (str[i] == 'r') sta[top++] = r;
else if (str[i] == 's') sta[top++] = s;
else if (str[i] == 't') sta[top++] = t;
else if (str[i] == 'K')
{
int t1 = sta[--top];
int t2 = sta[--top];
sta[top++] = (t1&&t2);
}
else if (str[i] == 'A')
{
int t1 = sta[--top];
int t2 = sta[--top];
sta[top++] = (t1 || t2);
}
else if (str[i] == 'N')
{
int t1 = sta[--top];
sta[top++] = (!t1);
}
else if (str[i] == 'C')
{
int t1 = sta[--top];
int t2 = sta[--top];
if (t1 == && t2 == )sta[top++] = ;
else sta[top++] = ;
}
else if (str[i] == 'E')
{
int t1 = sta[--top];
int t2 = sta[--top];
if ((t1 == && t2 == ) || (t1 == && t2 == )) sta[top++] = ;
else sta[top++] = ;
}
}
} bool solve()
{
for (p = ; p<; p++)
for (q = ; q<; q++)
for (r = ; r<; r++)
for (s = ; s<; s++)
for (t = ; t<; t++)
{
judge();
if (sta[] == )return false;
}
return true;
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
while (gets(str) && str[] != '')
{
if (solve()) cout << "tautology" << endl;
else cout << "not" << endl;
}
return ;
}

POJ 3295 Tautology(构造法)的更多相关文章

  1. POJ 3295 Tautology(构造法)

    题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  2. poj 3295 Tautology (构造)

    题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...

  3. POJ 3295 Tautology 构造 难度:1

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9580   Accepted: 3640 Descrip ...

  4. [ACM] POJ 3295 Tautology (构造)

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9302   Accepted: 3549 Descrip ...

  5. POJ 3295 Tautology (构造法)

    Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7716   Accepted: 2935 Descrip ...

  6. 构造 + 离散数学、重言式 - POJ 3295 Tautology

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

  7. POJ 3295 Tautology (构造题)

    字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...

  8. poj 3295 Tautology(栈)

    题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...

  9. 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)或 ...

随机推荐

  1. UIWebview于JS交互

    最近使用火车票网的限行网页,但是广告以及头部nav和地步footer都是我们现在所不需要的,所以决定使用js交互,下面所有代码都写在 webViewDidFinishLoad 里面 1.查看原网址的源 ...

  2. Winsock网络编程

    Winsock是Windows下网络编程的标准接口.使用Winsock编程的步骤一般是比较固定的. 首先要包含头文件#include <WinSock2.h>,同时要添加WS2_32.li ...

  3. mongodb mongotemplate聚合

    1.group by并且计算总数 @Test public void insertTest() { //测试数据 //insertTestData(); Aggregation agg = Aggre ...

  4. cf 459E

    cf459E 这题说的是 给定一个n点m条边的带边权的有向图,从中找出一条路径(可以带环),该路径包含的边数最多,并且要求路径中的权值必须严格递增,然后对边进行排序完个后采用dp去解特殊判断一下边权值 ...

  5. Python: 反方向迭代一个序列

    使用内置的reversed()函数 >>> a = [1, 2, 3, 4] >>> for x in reversed(a): ... print(x) out ...

  6. BP神经网络的Java实现(转载)

    神经网络的计算过程 神经网络结构如下图所示,最左边的是输入层,最右边的是输出层,中间是多个隐含层,隐含层和输出层的每个神经节点,都是由上一层节点乘以其权重累加得到,标上“+1”的圆圈为截距项b,对输入 ...

  7. 用CSS让字体在一行内显示不换行

    青枫 , 2012/07/13 18:08 , css样式设计 , 评论(0) , 阅读(2189) , Via 本站原创 大 | 中 | 小  当一行文字超过DIV或者Table的宽度的时候,浏览器 ...

  8. web前端----JavaScript(JS)函数

    函数 函数定义 JavaScript中的函数和Python中的非常类似,只是定义方式有点区别. // 普通函数定义 function f1() { console.log("Hello wo ...

  9. web前端----css选择器样式

    一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...

  10. 如何写出一个让人很难发现的bug?

    程序员的日常三件事:写bug.改bug.背锅.连程序员都自我调侃道,为什么每天都在加班?因为我的眼里常含bug. 那么如何写出一个让(坑)人(王)很(之)难(王)发现的bug呢? - 1 -新手开发+ ...