NOIP2008 火柴棒等式

题目: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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值