您的位置:首页 > 其它

NOIP2008 火柴棒等式

2015-09-19 16:38 393 查看
题目:http://www.luogu.org/problem/show?pid=1149#

分析:

不知道怎么做= -,于是暴力枚举,发现n^2最大只能1000,于是就设这个边界,于是就过了= -

代码:

#include <cstdio>
#include <algorithm>
using namespace std;
const int p[15]={6,2,5,5,4,5,6,3,7,6};
const long long int inf=1000;
int n,ans;
void work()
{
long long int i,j;
int sum,tmp;
n-=4;
for(i=0;i<=inf;i++)
{
for(j=0;j<=inf;j++)
{
sum=0;
tmp=i;
if(i==0) sum+=p[0];
else while(tmp>0)
{
sum+=p[tmp%10];
tmp/=10;
}
tmp=j;
if(j==0) sum+=p[0];
else while(tmp>0)
{
sum+=p[tmp%10];
tmp/=10;
}
tmp=i+j;
if(tmp==0) sum+=p[0];
else while(tmp>0)
{
sum+=p[tmp%10];
tmp/=10;
}
if(sum==n) ans++;
}
}
printf("%d",ans);
return;
}
int main()
{
scanf("%d",&n);
work();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: