POJ 3295 Tautology(构造法)
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(构造法)的更多相关文章
- POJ 3295 Tautology(构造法)
题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- poj 3295 Tautology (构造)
题目:http://poj.org/problem?id=3295 题意:p,q,r,s,t,是五个二进制数. K,A,N,C,E,是五个运算符. K:&& A:||N:! C:(!w ...
- POJ 3295 Tautology 构造 难度:1
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9580 Accepted: 3640 Descrip ...
- [ACM] POJ 3295 Tautology (构造)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9302 Accepted: 3549 Descrip ...
- POJ 3295 Tautology (构造法)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7716 Accepted: 2935 Descrip ...
- 构造 + 离散数学、重言式 - POJ 3295 Tautology
Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...
- POJ 3295 Tautology (构造题)
字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...
- poj 3295 Tautology(栈)
题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...
- 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)或 ...
随机推荐
- 如何正确的把 Java 数组 Array 转为列表 List
最近想把 java 数组转成 List,网上普遍的答案都是 Arrays.asList: String[] a = new String[] {"hello", "wor ...
- 图结构练习——判断给定图是否存在合法拓扑序列(sdutoj)
#include<stdio.h>#include<string.h>int d[15],map[15][15],vis[15];int main(){ int i,j, ...
- SDUT2826:名字的价值
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2806 名字的价值 Time Limit: 10 ...
- MongoDB和pymongo自用手册
[*] 本文出处:http://b1u3buf4.xyz/ [*] 本文作者:B1u3Buf4 [*] 本文授权:禁止转载 从自己的另一处博客移动过来.长期维护,不定期添加新内容. 前述和安装 mon ...
- soapUI-DataSink
1.1.1 DataSink 1.1.1.1 概述 – DataSink Option Description Properties DataSink属性表 Toolbar DataSink ...
- Keepalived+HAproxy实现高可用负载均衡
总概: Keepalived是一个类似于layer3, 4 & 5交换机制的软件,也就是我们平时说的第3层.第4层和第5层交换.Keepalived的作用是检测web服务器的状态, ...
- DirectShow SDK下载
http://blog.csdn.net/zx3517288/article/details/50547243 Q : GRMSDK_EN_DVD.iso 5 67.3MBGRMSDKIAI_EN_D ...
- unity3d API汇总
using UnityEngine; using System.Collections; public class AllFunction : MonoBehaviour { /* API Versi ...
- winform dataGridView DataGridViewComboBoxColumn 下拉框事件代码
有一个dataGridView ,有一列是DataGridViewComboBoxColumn .我用动态绑定,在绑定数据的时候.我们也给这一列绑定数据 在dataGridView的RowsAdded ...
- VMware coding Challenge
思路:这道题要观察,举个例子,1 2 * * 3 * 4 5 * * 6 7 * 8 * *, 用Stack,先序遍历,遇到数字就入栈,如果遇到 * *,说明栈顶节点是叶子节点,一条根到叶子的路径这 ...