
One day, AD1024 and Neli playing a game, they are using N matches to create equations: X+Y=Z(‘+’ and ‘=’ also created by using matches).
But they are too weak to work out every possible conditions, so they decide to ask you for help. You are a battlehardened programmer, so you can solve this problem by using programming.
Problem Description

Problem Analysis
This problem looks very hard, but it’s pretty easy. We can pre-process the number of matches that will be used creating number N.打表打表打表.
##AC Code
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int matches[10]={6,2,5,5,4,5,6,3,7,6};
int b[1001];
int ans;
int main(){
freopen("matches.in","r",stdin);
freopen("matches.out","w",stdout);
int n;
cin>>n;
n-=4;
for(int i=0;i<10;++i){
b[i]=matches[i];
}
for(int i=10;i<=999;++i){
b[i]=b[i/10]+b[i%10];
}
ans=0;
for(int i=0;i<=999;++i){
if(b[i]<n){
for(int j=0;j<=i;++j){
if(b[i]+b[j]+b[i-j]==n){
ans++;
}
}
}
}
cout<<ans;
fclose(stdin);
fclose(stdout);
return 0;
}




近期评论