啊!大虾们!看谁能给的最详细的解释
程序代码:
#include <stdio.h> #define MIN(a, b) ((a) < (b) ? a : b) int min4(int a, int b, int c, int d) { int min = 0; min = MIN(a, b); min = MIN(min, c); min = MIN(min, d); return min; } int main(void) { int top, left, bottom, right, width, i, j; scanf("%d", &width); for (i = 0; i < width; ++i) { for (j = 0; j < width; ++j) { top = i + 1; left = j + 1; bottom = width - i; right = width - j; printf("%-3d", min4(top, left, bottom, right)); } printf("\n"); } return 0; }
这是什么算法?
程序代码:
#include<stdio.h> int f(int row, int col, int n) { if(n - row - 1 < row) row = n - row - 1; if(n - col - 1 < col) col = n - col - 1; return ((row < col) ? row : col)+1 ; } int main() { int i, j, n; scanf("%d", &n); for(i = 0; i < n; i++, putchar('\n')) for(j = 0; j < n; j++) printf("%4d", f(i, j, n)); return 0; }
这又是什么算法,看的有点犯晕,给个解释,详细一点。
[ 本帖最后由 boyboyboyboy 于 2012-3-3 14:11 编辑 ]