该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*-----------------------------------*
搜索mm×nn矩阵的鞍点(saddle-points)
*------------------------------------*/
#include
#include
#define M(a,b) M[(a)*nn+(b)]
int main()
{
int i,j,mm,nn,*M,count=0;
int saddle(int* ,int,int,int,int);
printf("orders of matrix m,n = ");
scanf("%d,%d",&mm,&nn);
M=(int*)malloc(mm*nn*sizeof(int));
if(M==NULL)return-1;
//填充该矩阵:
for(i=0;i
printf("input line %d: ",i);
for(j=0;j
scanf("%d",&M(i,j));}
//搜索并输出鞍点:
printf("\n Saddle Point(s) List\n");
printf("------------------------\n");
for(i=0;i
for(j=0;j
if(saddle(M,mm,nn,i,j))
printf("%d: M(%d,%d) = %d\n",
++count,i,j,M(i,j));
printf("------------------------\n");
return 0;
}
int saddle(int*M,int mm,int nn,int i0,int j0)
{
//考察M(i0,j0)是否第i行最小元素:
int i,j,t=M(i0,j0);
for(j=0;j
if(t>M(i0,j))return 0;
//考察M(i0,j0)是否第j列最大元素:
for(i=0;i
if(t
//至此M(i0,j0)满足鞍点条件:
return 1;
}