蓝桥杯方格填数

    xiaoxiao2021-03-25  120

    方格填数 如下的10个格子    +--+--+--+    |  |  |  | +--+--+--+--+ |  |  |  |  | +--+--+--+--+ |  |  |  | +--+--+--+ (如果显示有问题,也可以参看【图1.jpg】) 填入0~9的数字。要求:连续的两个数字不能相邻。 (左右、上下、对角都算相邻) 一共有多少种可能的填数方案? 请填写表示方案数目的整数。

    注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

    #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std; int a[10]={0,1,2,3,4,5,6,7,8,9}; int jdg(int x,int y){ if(abs(a[x]-a[y])==1) return 0; else return 1; } int check(){ return jdg(0,3)&&jdg(0,4)&&jdg(0,5)&&jdg(0,1) &&jdg(1,4)&&jdg(1,5)&&jdg(1,6)&&jdg(1,2) &&jdg(2,5)&&jdg(2,6) &&jdg(3,7)&&jdg(3,8)&&jdg(3,4) &&jdg(4,7)&&jdg(4,8)&&jdg(4,9)&&jdg(4,5) &&jdg(5,8)&&jdg(5,9)&&jdg(5,6) &&jdg(6,9)&&jdg(7,8)&&jdg(8,9); } int main() { int cnt=0; do { if(check()) cnt++; }while(next_permutation(a,a+10)); printf("%d\n",cnt); return 0; }

    这里 感谢纪纲帮我调出的大错误。
    转载请注明原文地址: https://ju.6miu.com/read-12699.html

    最新回复(0)