标签:
1、题目如图所示,求出所有满足条件的情况:
这道题的第一思路就是找出隐含关系,然后暴力求解。假设所填空格从上往下,从左往右依次为a,b,c,d,e,f,g,h即:
a | b | 9 |
c | d | e |
f | g | h |
通过找隐含关系可以找到如下关系:
a+b=13;
0<=a<=4;
1<=f<=25;
e+h=5;
0<=e<=5;
接下来就是暴力求解,代码如下:
void main() { int a,b,c,d,e,f,g,h; for (a=0;a<=4;a++) { b=13-a; for (e=1;e<=5;e++)//e不能为0 { h=5-e; for (f=1;f<=25;f++) { c=(4-a)*f; g=4+h-f; if ((c-4)%e==0)//必须是整除关系 { d=(c-4)/e; if ((b-d*g) == 4) { cout << a << " "<< b <<" "<<9<<endl; cout << c << " "<< d <<" "<<e<<endl; cout << f << " "<< g <<" "<<h<<endl; } } } } } }
标签:
原文地址:http://www.cnblogs.com/LCCRNblog/p/4796095.html