poj 3295 Tautology (构造)
题目:http://poj.org/problem?id=3295
题意:p,q,r,s,t,是五个二进制数。
K,A,N,C,E,是五个运算符。
K:&&
A:||
N:!
C:(!w)||x
E:w==x
题意是让求如果对于五个数的所有情况一个式子总是恒为1,那么这个式子就是tautology。输出tautology。
否则输出not。
5个数,最多有2^5种情况。
判断式子是不是恒为1,只需要从后往前判断即可。
这题好长时间没看懂,代码也是看网上大神的
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
char str[];
int stack[]; int check()
{
int pp,qq,rr,ss,tt,n,i,top;
n=strlen(str);
for(pp = ; pp < ; pp++)
for(qq = ; qq < ; qq++)
for(rr = ; rr < ; rr++)
for(ss = ; ss < ; ss++)
for(tt = ; tt < ; tt++)
{
top = ;
for(i = n-; i >= ; i--)
{
if(str[i]=='q') stack[top++]=qq;
if(str[i]=='p') stack[top++]=pp;
if(str[i]=='r') stack[top++]=rr;
if(str[i]=='t') stack[top++]=tt;
if(str[i]=='s') stack[top++]=ss;
if(str[i]=='K') top--,stack[top-]=(stack[top-]&&stack[top]);
if(str[i]=='A') top--,stack[top-]=(stack[top-]||stack[top]);
if(str[i]=='N') stack[top-]=!stack[top-];
if(str[i]=='C') top--,stack[top-]=((!stack[top-])||stack[top]);
if(str[i]=='E') top--,stack[top-]=((stack[top-])==stack[top]);
}
if(top!=||stack[top-]!=)
return ;
} return ;
}; int main()
{
while(gets(str)&&str[]!='')
{
if(check())
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 构造 难度: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 Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...
- POJ 3295 Tautology(构造法)
http://poj.org/problem?id=3295 题意: 判断表达式是否为永真式. 思路: 把每种情况都枚举一下. #include<iostream> #include< ...
- POJ 3295 Tautology (构造题)
字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑 ...
- POJ 3295 Tautology (构造法)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7716 Accepted: 2935 Descrip ...
- poj 3295 Tautology(栈)
题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈, ...
- poj 3295 Tautology 伪递归
题目链接: http://poj.org/problem?id=3295 题目描述: 给一个字符串,字符串所表示的表达式中p, q, r, s, t表示变量,取值可以为1或0.K, A, N, C, ...
随机推荐
- Ajax 之【文件上传】
// 前台 var formData = new FormData(); var file = document.getElementById('myFile').files[0]; formData ...
- [译]GC专家系列1: 理解Java垃圾回收
原文链接:http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/ 了解Java的垃圾回收(GC)原 ...
- Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll
Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...
- Delphi代码优化
文章编目 1. 字符串优化 1.1. 不重复初始化 1.2. 使用SetLength预分配长字符串(AnsiString) 1.3. 字符串与动态数组的线程安全(Thread Safety) 1.4. ...
- 2014年辛星完全解读Javascript第五节 break和continue与错误处理
先说一下break和continue的主要用法吧,break用于跳出循环,continue用于跳过该循环中的一个迭代.简单的说,就是break直接从该语句跳出,但是continue不会跳出该循环语句, ...
- android模拟器打开时比较慢,Run As就找不到模拟器
1.运行中输入cmd,然后回车,调出command窗口 2.用cd,将目录切换到adb所在目录,然后输入adb kill-server ,adb start-server 3.adb devices就 ...
- ORA-12838: cannot read/modify an object after modifying it in parallel
insert /*+ append */ into my_all_objects select * from my_all_objects; select * from my_all_objects ...
- 使用Entity Framework时要注意的一些性能问题
http://diaosbook.com/Post/2012/12/9/performance-issue-in-select-one-or-few-colums-via-entityframewor ...
- 开发之前的思考-UI结构设计
UI结构设计遵循的一些要点 1.尽量不要让UI作为Camera的子物体 因为UI和摄像机敏感的关系,尽量不要将UI作为摄像机的子物体,避免出现一些因为透视(3D UI)等问题导致的视觉Bug. 2.尽 ...
- Good Bye 2015 A
Problem A:http://codeforces.com/problemset/problem/611/A A. New Year and Days 题意:某人要在2016年收集糖果,有两种不同 ...