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<iost…
题目网址:http://poj.org/problem?id=3295 题目: Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13231   Accepted: 5050 Description WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of the po…
Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9302   Accepted: 3549 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,…
Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9580   Accepted: 3640 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,…
字母:K, A, N, C, E 表示逻辑运算 字母:p, q, r, s, t 表示逻辑变量 0 或 1 给一个字符串代表逻辑表达式,如果是永真式输出tautology 否则输出not 枚举每个逻辑变量的值,5个变量,共2^5种情况,对于每种情况都为真则为永真式. 代码: /*************************************** Problem: 3295 User: Memory: 688K Time: 0MS Language: G++ Result: Accept…
Tautology 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 followin…
http://poj.org/problem?id=3295 题意: 判断表达式是否为永真式. 思路: 把每种情况都枚举一下. #include<iostream> #include<string> #include<cstring> using namespace std; ; int sta[MAXN]; char str[MAXN]; int p, q, r, s, t; void judge() { ; int len = strlen(str); ; i &g…
Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7716   Accepted: 2935 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,…
题目链接:http://poj.org/problem?id=3295 思路分析:判断逻辑表达式是否为永真式问题.根据该表达式的特点,逻辑词在逻辑变量前,类似于后缀表达式求值问题. 算法中使用两个栈,从表达式的后边开始处理表达式中每个字符:若为逻辑变量,使其入栈SR,否则从栈SR中弹出两个逻辑变量, 进行运算后的结果再入栈SR:直到处理完表达式所有的字符.(PS:使用栈可以很好的处理广义表类似的序列) 代码如下: #include <iostream> #include <stack&g…
题目链接: http://poj.org/problem?id=3295 题目描述: 给一个字符串,字符串所表示的表达式中p, q, r, s, t表示变量,取值可以为1或0.K, A, N, C, E 分别表示且,或,非,真蕴含,等值.问表达式是不是永真的,如果是输出“tautology”,否则输出“not”. 解题思路: 这里借用到了递归的本质,也就是对栈的模拟,用递归进行压栈,求表达式的值,再加上对变量状态压缩进行枚举. #include <cstdio>//本代码用G++交就ac,c+…
点击打开链接 Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8127   Accepted: 3115 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…
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive…
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he ca…
link:http://acm.hdu.edu.cn/showproblem.php?pid=4671 其实是不难的那种构造题,先排第一列,第二列从后往前选. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <algorithm> #…
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a. Let number i be in positions xi, yi (xi < yi) i…
这是一道蛮基础的构造题. - k         +(k - 1)      -(k - 2) 1 + k ,    1 ,         k ,             2,    ................... \  /        \  /           \  / k          k-1          k-2 如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2 这样下来,最后一个数字就是一个中间的数字,过程就…
3097: Hash Killer I Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 963  Solved: 364[Submit][Status][Discuss] Description 这天天气不错,hzhwcmhf神犇给VFleaKing出了一道题: 给你一个长度为N的字符串S,求有多少个不同的长度为L的子串. 子串的定义是S[l].S[l + 1].... S[r]这样连续的一段. 两个字符串被认为是…
这场CF怎么这么多构造题…… 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c_i$ 变成 $c_i'=c_{i-1}+c_{i+1}-c_i$.问 $c$ 能否在若干次操作后变成 $t$. $1\le n\le 10^5,1\le c_i,t_i\le 2\times 10^9$. 很容易考虑差分.我们设 $d_i=c_i-c_{i-1},s_i=t_i-t_{i-1}(2\le…
旅游的Final柱 题目连接: http://acm.uestc.edu.cn/#/problem/show/1288 Description 柱神要去打Final啦~(≧▽≦)/~啦啦啦 柱神来到了异国他乡的普吉岛,柱神决定好好游览一番. 普吉岛的景点编号为11到NN,景点之间由双向的道路连接着,所有的道路的长度都是11. 柱神希望访问所有的景点,但是又不想耽搁太长的时间,所以柱神决定每天访问一个景点. 为了好好陶冶情操,柱神并不在路上花费太多的时间,所以柱神不会在连续的两天访问两个最短距离超…
题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指可以删掉数后再判断. 思路 略神的数学构造题... 官方题解: An equivalent definition for almost unique, is arrays with at least ⌊ 2n / 3⌋ different elements. The idea is to split…
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5355 题面: Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1632    Accepted Submission(s): 273 Special Judge Problem Description There are m…
比赛时候还是太慢了……要是能做快点就能上分了 Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 11 to nn. For every edge ee of this tree, Monocarp has written two numbers: the ma…
B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错了... 用1 2 来构造 可以先枚举一些数来找找规律. 1 1 2 2 3 1 1 1    2 1 1 4 .... 可以发现每一个数都是 n/2+1 的可能, 所以反过来推过去就是 (s-1)*2  或者(s-1)*2+1 这个(s-1)*2+1的答案才是正确答案 因为 这个s可以==1 #i…
题面 传送门:https://www.luogu.org/problemnew/show/P1268 Solution 这是一道极其巧妙的构造题 先做一个约定[i,j]表示从i到j的距离 我们可以先从n=2,也就是最简单的情况来切入这道题 对于n=2,答案显然是[1,2] 接下来考虑n=3 如下图所示 这棵树一定是长成这样的 也就是说三这个节点一定是插在1与2两个节点之间的 我们可以发现,3节点的插入使得树的权值增加了([1,3]+[2,3]-[1,2])/2 (即紫线与蓝线的权值和减去绿线除以…
Codeforces 题目传送门 & 洛谷题目传送门 obviously,难度高一点的构造题对我来说都是不可做题 首先考虑将排列拆成一个个置换环,也就是 \(\forall i\) 连边 \(i\to p_i\),显然这样我们可以得到一个个环. 首先考虑怎样同时处理两个置换环,假设有两个环,长度分别为 \(p,q\),元素分别为 \(x_1,x_2,\cdots,x_p;y_1,y_2,\cdots,y_q\).我们考虑以下步骤同时将这两个环中所有元素复位: 交换 \(x_1,y_1\),两个置…
Tautology Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10482   Accepted: 3982 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…
  Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10437   Accepted: 3963 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 W…
Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10841   Accepted: 5085 Description A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the…
题目链接:http://poj.org/problem?id=3295 题意: 输入由p.q.r.s.t.K.A.N.C.E共10个字母组成的逻辑表达式, 其中p.q.r.s.t的值为1(true)或0(false),即逻辑变量: K.A.N.C.E为逻辑运算符, K --> and:  x && y A --> or:  x || y N --> not :  !x C --> implies :  (!x)||y E --> equals :  x==y…
编程题#1 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 下面的程序输出结果是: 1 2 6 7 8 9 请填空: #include <iostream> #include <iterator> #include <set> using namespace std; int main() { int a[] = {8,7,8,9,6,2,1};…