Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10428 | Accepted: 3959 |
Description
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.
The meaning of a WFF is defined as follows:
- 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.
| Definitions of K, A, N, C, and E |
| w x | Kwx | Awx | Nw | Cwx | Ewx |
| 1 1 | 1 | 1 | 0 | 1 | 1 |
| 1 0 | 0 | 1 | 0 | 0 | 0 |
| 0 1 | 0 | 1 | 1 | 1 | 0 |
| 0 0 | 0 | 0 | 1 | 1 | 1 |
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
ApNp
ApNq
0
Sample Output
tautology
not
实在是读不懂什么意思,后来找篇博客,才知道什么意思,英语好渣#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
using namespace std; const int Max=1100000; int Arr[6];
int top;
string str;
stack<int>a;
void Bit(int num)
{
int top=0;
memset(Arr,0,sizeof(Arr));
while(num)
{
Arr[top++]=num%2;
num/=2;
}
}
bool Jud(char s)
{
switch(s)
{
case 'p':a.push(Arr[0]);break;
case 'q':a.push(Arr[1]);break;
case 'r':a.push(Arr[2]);break;
case 's':a.push(Arr[3]);break;
case 't':a.push(Arr[4]);break;
default :return 0;
}
return 1;
}
void Count(char s)
{
switch(s)
{
case 'K':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push(x&&y);
}
break;
case 'A':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push(x||y);
}
break;
case 'N':
{
int x=a.top();a.pop();
a.push(!x);
}
break;
case 'C':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push((!x)||y);
}
break;
case 'E':
{
int x=a.top();a.pop();
int y=a.top();a.pop();
a.push(x==y);
}
break;
}
}
bool Cal()
{
int len=str.length();
for(int i=0;i<=31;i++)
{
Bit(i);
for(int j=len-1;j>=0;j--)
{
if(!Jud(str[j]))
{
Count(str[j]);
}
}
int x=a.top();
a.pop();
if(!x)
return false;
}
return true;
}
int main()
{
while(cin>>str)
{
if(str=="0")
break;
if(Cal())
{
cout<<"tautology"<<endl;
}
else
{
cout<<"not"<<endl;
}
} }
版权声明:本文为博主原创文章,未经博主允许不得转载。
Tautology 分类: POJ 2015-06-28 18:40 10人阅读 评论(0) 收藏的更多相关文章
- 灰度世界算法(Gray World Algorithm) 分类: 图像处理 Matlab 2014-12-07 18:40 874人阅读 评论(0) 收藏
人的视觉系统具有颜色恒常性,能从变化的光照环境和成像条件下获取物体表面颜色的不变特性,但成像设备不具有这样的调节功能, 不同的光照环境会导致采集的图像颜色与真实颜色存在一定程度的偏差,需要选择合适的颜 ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- Emag eht htiw Em Pleh 分类: POJ 2015-06-29 18:54 10人阅读 评论(0) 收藏
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2937 Accepted: ...
- 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏
Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- Binary Indexed Tree 2D 分类: ACM TYPE 2014-09-01 08:40 95人阅读 评论(0) 收藏
#include <cstdio> #include <cstdlib> #include <climits> #include <cstring> # ...
- Ubuntu vim+ ctags(包含系统函数) + taglist 配置 分类: vim ubuntu 2015-06-09 18:19 195人阅读 评论(0) 收藏
阅读大型代码,我们经常需要打开很多的代码文件,搜索各种定义.windows下用惯了ide的朋友,转战Linux的时候可能会觉得很难受,找不到合适的阅读工具.其实万能的vim就可以实现.下面介绍一下vi ...
- mount命令以及mount ntfs硬盘权限权限与显示的问题 分类: shell ubuntu 2014-11-08 18:29 148人阅读 评论(0) 收藏
sudo mount -t 文件系统类型 -o 可设置选项 设备路经 访问路经 #常用文件类型如下: iso9660 光驱文件系统, vfat fat/fat32分区, ntfs ntfs分区, sm ...
- 由 argv引出的main参数 分类: C/C++ 2014-11-08 18:00 154人阅读 评论(0) 收藏
我们经常用的main函数都是不带参数的.因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这 ...
- [leetcode] Reverse Linked List 分类: leetcode 算法 2015-07-09 18:44 2人阅读 评论(0) 收藏
反转链表:比较简单的问题,可以遍历也可以递归. # Definition for singly-linked list. class ListNode: def __init__(self, x): ...
随机推荐
- php:PHPExcel导出excel表格
一.动态生成的内容如何能当成文件来下载呢? 方法:1.将Content-Type设置成application/octet-stream就可以了,即[header('Content-Type: appl ...
- 学习OpenCV——hand tracking手势跟踪
这几日,岛上风云突变,我这个倒霉孩子终究木有躲过感冒的魔掌,中枪鸟~~~ 这几天只写了个简单的手势跟踪的代码. 原理是:背景差分+肤色检测. 背景差分:取前30帧图像取平均值,计算前30帧之差的和,再 ...
- java Servlet中的过滤器Filter
web.xml中元素执行的顺序listener->filter->struts拦截器->servlet. 1.过滤器的概念 Java中的Filter 并不是一个标准的Servlet ...
- mysql的binlog安全删除
理论上,应该在配置文件/etc/my.cnf中加上binlog过期时间的配置项,expire_logs_days = 10 但是如果没有加这一项,随着产生越来越多的binlog,磁盘被吃掉了不少.可以 ...
- Lintcode: Subarray Sum Closest
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first nu ...
- struts2 标签字体大小
<style type="text/css"> label{ font-size: 20px; } </style> <s:textfield nam ...
- bzoj4238 电压
首先先直接对图进行二染色,dfs染完色后,有的边为搜索树边,有的为非树边,当非树边连接的两头的点为异色的时候,那么很明显这条非树边和树边构成的环上的边必然不可能成为答案:如果非树边的两端的点同色,那么 ...
- 自定义FragmentTabHost--实现View重复加载问题
1,接着上篇的Fragment+FragmentTabHost搭建简单的底部功能切换框架,效果如下: 结果在项目中用到的时候发现Fragment+FragmentTabHost实现的时候每一次切换底部 ...
- 封装cookie localStorage sessionStorage
var cookie = function(name, value, options) { if (typeof value !== 'undefined') { options = options ...
- [MacOSX]
When i run svn up in the folder, i got these error: svn: Error converting entry in directory 'XXXXX' ...