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 |
Re:为什么会TLE呢??In Reply To:为什么会TLE呢?? Posted by:yangkeao at 2016-07-29 21:29:41 > 代码如下 > > > #include <cstdio> > using namespace std; > char s[7000]; > bool calc(char s[], int pos, bool p, bool q, bool r, bool _s, bool t) { > if (s[pos] == 'N') return !calc(s,pos+1, p, q, r, _s, t); > else if (s[pos] == 'K') return calc(s, pos + 1, p, q, r, _s, t) && calc(s, pos + 2, p, q, r, _s, t); > else if (s[pos] == 'A') return calc(s, pos + 1, p, q, r, _s, t) || calc(s, pos + 2, p, q, r, _s, t); > else if (s[pos] == 'C') return (!(!calc(s, pos + 1, p, q, r, _s, t)) || calc(s, pos + 2, p, q, r, _s, t)); > else if (s[pos] == 'E') return !(calc(s, pos + 1, p, q, r, _s, t) ^ calc(s, pos + 2, p, q, r, _s, t)); > else 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; > } > int main() { > scanf("%s", &s); > while (s[0] != '0') { > bool k = 1; > for (int arg = 0; arg < 32; arg++) { > bool p = arg & 1; > bool q = (arg & 2)/2; > bool r = (arg & 4)/4; > bool _s = (arg & 8)/8; > bool t = (arg & 16)/16; > if (!calc(s, 0, p, q, r, _s, t)) k = 0; > } > if (k) printf("tautology\n"); > else printf("not\n"); > scanf("%s", &s); > } > return 0; > } > > 为什么会TLE呢?很奇怪。 逻辑错了┭┮﹏┭┮,然后加上记忆化 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator