POJ 3295
来源:互联网 发布:淘宝司法拍卖车辆 编辑:程序博客网 时间:2024/05/01 18:43
Tautology
WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the possible symbols K, A, N, C, E, p, q, r, s, t. A Well-formed formula (WFF) is any string of these symbols obeying the following rules:
- p, q, r, s, and t are WFFs
- if w is a WFF, Nw is a WFF
- if w and x are WFFs, Kwx, Awx, Cwx, and Ewx are WFFs.
- p, q, r, s, and t are logical variables that may take on the value 0 (false) or 1 (true).
- K, A, N, C, E mean and, or, not, implies, and equals as defined in the truth table below.
A tautology is a WFF that has value 1 (true) regardless of the values of its variables. For example, ApNp is a tautology because it is true regardless of the value of p. On the other hand, ApNq is not, because it has the value 0 for p=0, q=1.
You must determine whether or not a WFF is a tautology.
Input
Input consists of several test cases. Each test case is a single line containing a WFF with no more than 100 symbols. A line containing 0 follows the last case.
Output
For each test case, output a line containing tautology or not as appropriate.
Sample Input
ApNpApNq0
Sample Output
tautologynot
Source
总结:
递归题,表达式,永真式
做了两个版本
WA了很多次,原来是把题目意思看错了。开始理解为不管任何pqrst值,计算结果都一样的是tautology。
AC代码1
后来看了discuss的提示,给出了另一个很精简的写法
AC代码2
在网上,还发现一个用位运算的更精简的写法,学习了。
http://www.cnblogs.com/asuran/archive/2009/09/28/1575379.html
- POJ 3295
- POJ 3295
- poj 3295
- poj 3295
- poj 3295
- POJ 3295
- poj-3295
- poj-3295
- poj 3295
- poj 3295
- POJ--3295
- poj 3295
- poj 3295
- POJ 3295 Tautology 模拟
- poj 3295 构造
- POJ-3295-Tautology
- POJ 3295 Tautology
- POJ 3295 Tautology
- 浅谈SOA (转)
- DFM文件与标准文本文件转换
- 浅淡HTTP协议三--断点续传
- VBIRD BASIC 2
- SQLServer 存储过程简介与使用方法
- POJ 3295
- 显示源码相关命令 lsa lsc lsp lsf
- 企业老板十二大谎话排行榜
- 浅淡HTTP协议四--关于Chunked编码
- 临界区,互斥,信号量
- 连接数据库查询(OpenRowSet)
- SQLServer 表值函数与标量值函数 定义方式与调用区别
- NETXML注释概述
- 用Socket类实现HTTP协议客户端应用