打表

博弈论记的笔记直接关机给没了,挺桑心的。算了,不重写了吧。

附上链接:https://blog.csdn.net/Hi_KER/article/details/81188352

对于数据小又容易超时的题,可以采取打表法

打表就是将所有输入情况的答案保存在代码中,输入数据后直接输出就可以了

打表法具有快速,易行(可以写暴力枚举程序)的特点,缺点是代码可能太大,或者情况覆盖不完

对于不会超时,数据规模适合打表,为了简洁你也可以打表

问题:https://www.luogu.org/problemnew/show/P1149

#include<bits/stdc++.h>
using namespace std;
int res[2000];
int main(){
	int a[10]={6,2,5,5,4,5,6,3,7,6};
	res[0]=6;
	for(int i=1;i<=2000;i++){
		int k=i;int temp=0;
		
		while(k){
			temp+=a[k%10];
			k/=10;
		}
		res[i]=temp;
	}
	int n=0;
	again:
	int num=0;
	for(int i=0;i<=999;i++){
		for(int j=0;j<=999;j++){
			if(n==res[i]+res[j]+res[i+j]+4)
			num++;
		}
	}
	cout<<num<<endl;
	if(n<24) {
		n++;
		goto again;
	}
	return 0;
} 

提交:

#include<bits/stdc++.h>
using namespace std;
int a[100]={0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,8,9,6,9,29,39,38,65,88,128};
int main(){
	int n;
	cin>>n;
	cout<<a[n]<<endl;
	return 0;
}

。。。。没写完,以后再修改吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章