蓝桥杯六角填数

六角填数

 

    如图【1.png】所示六角形中,填入1~12的数字。

 

    使得每条直线上的数字之和都相同。

 

    图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少?

 


#include <iostream>  
#include <algorithm>  
#include <string.h>  
#include <math.h>  
using namespace std;  
int main()  
{  
   int a,b,c,d,e,f,g,h,n;  
    int flag=0;  
    int x[6];  
    for(a=1;a<=12&&flag==0;a++)  
        for(b=1;b<=12&&flag==0;b++)  
           for(c=1;c<=12&&flag==0;c++)  
                for(d=1;d<=12&&flag==0;d++)  
                  for(e=1;e<=12&&flag==0;e++)  
                        for(f=1;f<=12&&flag==0;f++)  
                            for(g=1;g<=12&&flag==0;g++)                                 
							   for(h=1;h<=12&&flag==0;h++)  
                                   for(n=1;n<=12&&flag==0;n++)  
                                   {  
                                       x[0]=8+a+b+c;
									   x[1]=1+a+n+e;
									   x[2]=1+b+d+h;  
                                       x[3]=8+n+f+3;
									   x[4]=c+d+g+3;
									   x[5]=e+f+g+h;  
                                       if(x[0]==x[1]&&x[0]==x[2]&&x[0]==x[3]&&x[0]==x[4]&&x[0]==x[5]&&x[1]==x[2]&&x[1]==x[3]&&x[1]==x[4]&&x[1]==x[5]  
                                       &&x[2]==x[3]&&x[2]==x[4]&&x[2]==x[5]&&x[3]==x[4]&&x[3]==x[5]&&x[4]==x[5])  
                                       {  
                                           flag=1;break;  
                                       }  
                                   }  
    cout << n ;                     
    return 0;  
}  

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值