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): ...
随机推荐
- c#操作Excel时,抛出异常:“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”
我们开发环境下,使用excel导入数据到数据库中,编译的软件起初是x86 方式,起初并未发现什么问题,一切很正常: 程序该进的过程: 后来导入文件一次就要读取几百G的数据导入数据库中,使用编译的X86 ...
- PostgreSQL Monitor pg_activity
PostgreSQL Monitor pg_activity Command line tool for PostgreSQL server activity monitoring. https:// ...
- PostgreSQL Replication之第十章 配置Slony(5)
10.5 给复制添加表和管理的问题 一旦我们增加了此表到系统中,我们可以将它添加到复制设置.这样做有点复杂.首先,我们必须创建我们自己的新表集合并把这个和我们已经有的表合并.因此,过一段时间,我们将有 ...
- Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- 利用并查集求最大生成树和最小生成树(nlogn)
hdu1233 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- nyist 626 intersection set
http://acm.nyist.net/JudgeOnline/problem.php?pid=626 intersection set 时间限制:1000 ms | 内存限制:65535 KB ...
- Ubuntu 16.04 LTS Final Beta
期待已久的Ubuntu LTS 版本开放了公测版本 Ubuntu 16.04 (Xenial Xerus) Daily Build(http://cdimage.ubuntu.com/daily-l ...
- web处理jsp文件的三个阶段
web处理jsp文件的三个阶段 翻译阶段(servlet) 编译阶段(class) 执行阶段(print页面标签) 推送html到浏览器
- bzoj1758 [Wc2010]重建计划 & bzoj2599 [IOI2011]Race
两题都是树分治. 1758这题可以二分答案avgvalue,因为avgvalue=Σv(e)/s,因此二分后只需要判断Σv(e)-s*avgvalue是否大于等于0,若大于等于0则调整二分下界,否则调 ...
- register_shutdown_function
脚本时常死掉,而且并不总是那么好看. 我们可不想给用户显示一个致命错误,又或者一个空白页(在display_errors设为off的情况下) . PHP中有一个叫做 register_shutdow ...