2012年蓝桥杯软件设计大赛河南省初赛试题和答案 下载本文

15 int n3 = x2 * y1; 16 int n4 = x2 * y2; 17

18 r[3] = n1 % base;

19 r[2] = n1 / base + n2 % base + n3 % base;

20 r[1] = n3 / base + n2 / base + n4 % base; // 填空 21 r[0] = n4 / base; 22

23 r[1] += r[2] / base; // 填空 24 r[2] = r[2] % base; 25 r[0] += r[1] / base; 26 r[1] = r[1] % base; 27 }

28 int main(int argc, char* argv[]) 29 {

30 int x[] = {0,0,0,0};

31 bigmul(87654321, 12345678, x);

32 printf(\, x[0],x[1],x[2],x[3]); 33 system(\); 34 return 0; 35 }

七、放棋子

今有 6 x 6 的棋盘格。其中某些格子已经预先放好了棋子。现在要再放上去一些,使得:每行每列都正好有3颗棋子。我们希望推算出所有可能的放法。下面的代码就实现了这个功能。

初始数组中,“1”表示放有棋子,“0”表示空白。

1 #include 2 #include 3

4 using namespace std; 5

6 int N = 0;

7 bool CheckStoneNum(int x[][6]) 8 {

9 for(int k=0; k<6; k++) 10 {

11 int NumRow = 0; 12 int NumCol = 0;

13 for(int i=0; i<6; i++) 14 {

15 if(x[k][i]) NumRow++; 16 if(x[i][k]) NumCol++; 17 }

18 if(NumRow != 3 || NumCol != 3)// 填空 19 return false; 20 }

21 return true; 22 }

23 int GetRowStoneNum(int x[][6], int r) 24 {

25 int sum = 0;

26 for(int i=0; i<6; i++) if(x[r][i]) sum++; 27 return sum; 28 }

29 int GetColStoneNum(int x[][6], int c) 30 {

31 int sum = 0;

32 for(int i=0; i<6; i++) if(x[i][c]) sum++; 33 return sum; 34 }

35 void show(int x[][6]) 36 {

37 for(int i=0; i<6; i++) 38 {

39 for(int j=0; j<6; j++) printf(\, x[i][j]); 40 printf(\); 41 }

42 printf(\); 43 }

44 void f(int x[][6], int r, int c);

45 void GoNext(int x[][6], int r, int c) 46 {

47 if(c<6)

48 f(x, r, c+1); // 填空 49 else

50 f(x, r+1, 0); 51 }

52 void f(int x[][6], int r, int c) 53 {

54 if(r==6) 55 {

56 if(CheckStoneNum(x)) 57 {

58 N++; 59 show(x); 60 }

61 return;

62 }

63 if(x[r][c]) // 填空------已经放有了棋子 64 {

65 GoNext(x,r,c); 66 return; 67 }

68 int rr = GetRowStoneNum(x,r); 69 int cc = GetColStoneNum(x,c); 70 if(cc>=3) // 本列已满 71 GoNext(x,r,c);

72 else if(rr>=3) // 本行已满 73 f(x, r+1, 0); 74 else 75 {

76 x[r][c] = 1; 77 GoNext(x,r,c); 78 x[r][c] = 0;

79 if(!(3-rr >= 6-c || 3-cc >= 6-r)) // 本行或本列严重缺子,则本格不能空着!

80 GoNext(x,r,c); 81 } 82 }

83 int main(int argc, char* argv[]) 84 {

85 int x[6][6] = { 86 {1,0,0,0,0,0}, 87 {0,0,1,0,1,0}, 88 {0,0,1,1,0,1}, 89 {0,1,0,0,1,0}, 90 {0,0,0,1,0,0}, 91 {1,0,1,0,0,1} 92 };

93 f(x, 0, 0);

94 printf(\, N); 95 system(\); 96 return 0; 97 }

八、密码发生器

在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,容易被破解,不安全;如果设置不好记的密码,又担心自己也会忘记;如果写在纸上,担心纸张被别人发现或弄丢了...