本文主要是介绍骗分技巧之打表出省一,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
例题一
例题二
例题一
P1044 [NOIP2003 普及组] 栈https://www.luogu.com.cn/problem/P1044当我们在考场上不知道卡特兰数,但我们可以骗分。
先写出以下代码:
#include<bits/stdc++.h>
using namespace std;
long long n, ans, now;
bool V[10];
void dfs(int stepu, int stepo) {if (stepu >= n and stepo >= n) {ans += (now == 0);return;}if (stepo > n or stepu > n) return;if (stepo < n and now) {now--;dfs(stepu, stepo + 1);now++;}if (stepu < n) {now++;dfs(stepu + 1, stepo);now--;}
}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin >> n;dfs(0, 0);cout << ans << endl;return 0;
}
关注到题目里写着 n <= 18
必定超时,但我们可以打表
依次运行n=1~18的答案得到下表:
n | 答案 |
1 | 1 |
2 | 2 |
3 | 5 |
4 | 14 |
5 | 42 |
6 | 132 |
7 | 429 |
8 | 1430 |
9 | 4862 |
10 | 16796 |
11 | 58786 |
12 | 208012 |
13 | 742900 |
14 | 2674440 |
15 | 9694845 |
16 | 35357670 |
17 | 129644790 |
18 | 477638700 |
得到打表程序:
#include<bits/stdc++.h>
using namespace std;
long long arr[] = {0, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700};
int main(){int n;cin >> n;cout << arr[n] << endl;return 0;
}
一提交发现:
例题二
[CSP-J 2022] 逻辑表达式[CSP-J 2022] 逻辑表达式https://www.luogu.com.cn/problem/P8815?contestId=90215我考场上逻辑表达式的值会做,但后面的不会(谁叫我是XXS呢)
但我也去打表了。
哈哈哈。
代码见下:
#include<bits/stdc++.h>
using namespace std;
string s;
int main() {freopen("expr.in","r",stdin);freopen("expr.out","w",stdout);cin >> s;if (s == "1") cout << "1\n0 0";else if(s == "0") cout << "0\n0 0";else if(s == "(1)") cout << "1\n0 0";else if(s == "(0)") cout << "0\n0 0";else if(s == "1&1") cout << "1\n0 0";else if(s == "1&0") cout << "0\n0 0";else if(s == "0&1") cout << "0\n1 0";else if(s == "0&0") cout << "0\n1 0";else if(s == "1|1") cout << "1\n0 1";else if(s == "1|0") cout << "1\n0 1";else if(s == "0|1") cout << "1\n0 0";else if(s == "0|0") cout << "0\n0 0";else if(s == "((1))") cout << "1\n0 0";else if(s == "((0))") cout << "0\n0 0";else if(s == "(1&1)") cout << "1\n0 0";else if(s == "(1&0)") cout << "0\n0 0";else if(s == "(0&1)") cout << "0\n1 0";else if(s == "(0&0)") cout << "0\n1 0";else if(s == "(1|1)") cout << "1\n0 1";else if(s == "(1|0)") cout << "1\n0 1";else if(s == "(0|1)") cout << "1\n0 0";else if(s == "(0|0)") cout << "0\n0 0";else if(s == "(1)&1") cout << "1\n0 0";else if(s == "(1)&0") cout << "0\n0 0";else if(s == "(0)&1") cout << "0\n1 0";else if(s == "(0)&0") cout << "0\n1 0";else if(s == "(1)|1") cout << "1\n0 1";else if(s == "(1)|0") cout << "1\n0 1";else if(s == "(0)|1") cout << "1\n0 0";else if(s == "(0)|0") cout << "0\n0 0";else if(s == "1&(1)") cout << "1\n0 0";else if(s == "1&(0)") cout << "0\n0 0";else if(s == "0&(1)") cout << "0\n1 0";else if(s == "0&(0)") cout << "0\n1 0";else if(s == "1|(1)") cout << "1\n0 1";else if(s == "1|(0)") cout << "1\n0 1";else if(s == "0|(1)") cout << "1\n0 0";else if(s == "0|(0)") cout << "0\n0 0";else if(s == "1&1|1") cout << "1\n0 1";else if(s == "1&1|0") cout << "1\n0 1";else if(s == "1&1&1") cout << "1\n0 0";else if(s == "1&1&0") cout << "0\n0 0";else if(s == "1&0|1") cout << "1\n0 0";else if(s == "1&0|0") cout << "0\n0 0";else if(s == "1&0&1") cout << "0\n1 0";else if(s == "1&0&0") cout << "0\n1 0";else if(s == "0&1|1") cout << "1\n1 0";else if(s == "0&1|0") cout << "0\n1 0";else if(s == "0&1&1") cout << "0\n2 0";else if(s == "0&1&0") cout << "0\n2 0";else if(s == "0&0|1") cout << "1\n1 0";else if(s == "0&0|0") cout << "0\n1 0";else if(s == "0&0&1") cout << "0\n2 0";else if(s == "0&0&0") cout << "0\n2 0";else if(s == "1|1|1") cout << "1\n0 1";else if(s == "1|1|0") cout << "1\n0 1";else if(s == "1|1&1") cout << "1\n0 1";else if(s == "1|1&0") cout << "1\n0 1";else if(s == "1|0|1") cout << "1\n0 1";else if(s == "1|0|0") cout << "1\n0 1";else if(s == "1|0&1") cout << "1\n1 1";else if(s == "1|0&0") cout << "1\n1 1";else if(s == "0|1|1") cout << "1\n0 1";else if(s == "0|1|0") cout << "1\n0 1";else if(s == "0|1&1") cout << "1\n0 0";else if(s == "0|1&0") cout << "0\n0 0";else if(s == "0|0|1") cout << "1\n0 0";else if(s == "0|0|0") cout << "0\n0 0";else if(s == "0|0&1") cout << "0\n1 0";else if(s == "0|0&0") cout << "0\n1 0";else if(s == "0&(1|0)|(1|1|1&0)") cout << "1\n1 2";else if(s == "(0|1&0|1|1|(1|1))&(0&1&(1|0)|0|1|0)&0") cout <<"0\n2 3";else if(s == "(((((1&(0&0|1))&(1|0|0)|1|(0&((0|(0|1)&1)|1|0))&((1|(1|1)&(1&0)&(1|1))|(1|0)|1)&((((((1|0)|0|0)&(1|((1&1&1)&(1|1))&0|0&0)|1)|1&0)&(0|0)|(0&(1|1))&1&(1|1)|0|1&0)&((0|1&0|1)&1)&(1|(1|0)&0))&(1&((1&0|1)|0&0)&((0|0)|0&0)|(1|((1|1)|1)&1&0)&1))|1|1)&((((((0&0)&(0|(0|1)|1&1)|0&0)|1)&(1|(1&0)&0))&(0|(0|0)|0)|(0|0)|0&1|((0&1|1)|0)&0)|((1|1|0&0)|(1&0&1)&(1&(1|0)|(0|1)&(1|0))|(((0&1)&0&1|(1&0)&0)|((0|1)|0)|1)|(1&1)&0)&(0&0)&(1|1))|((((0|0)|(0|0)|0)&0)&((0|(0|0)&0)|((1&(0|1&0)|1)|1)|0))&(1|0|1))|(0&((((1&0|1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&0|1)&(0|1)&(0|0))&((((0|1)&((0|1&0&0|1)&(1|1)|1))&((1&0&0|1&0)|(1|0)|(0|1)|1&1)&((0&0|1&0|(0|0)&1)|1)|(((0&1)&(1|0&1&1))&1)&(((1|(0|0)|1)|(0&1)&((1|1)|1|0))|(0|0|0)&1&0)|(1|1&1|0)&((1|1)&0)&((1&0|1)|0))&((0|1&(0&0|0&0))|(1|1)&0|1))&((0&1)&((0|0&1)|1&1&((0|(1&1)&0)&0&1)&1)|(0&1)&0)|(0|(0|0&0)&0)&(0&1|0)&(1|1))&((1|1)&1|(((0|0)|0&0)|((1&1|(1&0)&1)|0)|((0&0)&0)&0&1|1|1)|(1|0)&0&0)") cout << "1\n22 36";else {cout << rand()%2<<endl;long long a = 0,b = 0;for(int i = 0; i < s.size(); i++) {if(s[i] == '|') a++;if(s[i] == '&') b++;}cout << rand()%(b/2)<< ' ' << rand()%(a/2) << endl;}return 0;
}
我的帖子:T3这样能拿20分吗
这篇关于骗分技巧之打表出省一的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!