| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
贴上正确的代码In Reply To:Re:为什么会TLE呢?? Posted by:yangkeao at 2016-07-31 21:37:32 >
> 逻辑错了┭┮﹏┭┮,然后加上记忆化
#include <cstdio>
using namespace std;
char s[7000];
bool p, q, r, _s, t;
int n,pos;
bool calc() {
if (s[pos] == 'p') return p;
else if (s[pos] == 'q') return q;
else if (s[pos] == 'r') return r;
else if (s[pos] == 's') return _s;
else if (s[pos] == 't') return t;
else if (s[pos] == 'K') {
pos++;
bool w = calc();
pos++;
bool x = calc();
return w&x;
}
else if (s[pos] == 'A') {
pos++;
bool w = calc();
pos++;
bool x = calc();
return w|x;
}
else if (s[pos] == 'N') {
pos++;
bool w = calc();
return !w;
}
else if (s[pos] == 'C') {
pos++;
bool w = calc();
pos++;
bool x = calc();
return (!w) | x;
}
else if (s[pos] == 'E') {
pos++;
bool w = calc();
pos++;
bool x = calc();
return w == x;
}
}
int main() {
scanf("%s", &s);
while (s[0] != '0') {
bool k = 1;
while (s[n]) {
n++;
}
for (int arg = 0; arg < 32; arg++) {
p = arg & 1;
q = (arg & 2) / 2;
r = (arg & 4) / 4;
_s = (arg & 8) / 8;
t = (arg & 16) / 16;
pos = 0;
if (!calc()) k = 0;
}
if (k) printf("tautology\n");
else printf("not\n");
for (int i = 0; i < n; i++) {
s[i] = 0;
}
n = 0;
scanf("%s", &s);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator