杭电acm2827

[复制链接]
查看11 | 回复1 | 2011-5-11 09:14:35 | 显示全部楼层 |阅读模式
这道题就是算个行列式然后mod一个数
#include
#include
#include
void getarray(int n);
void showarray(int n);
double getresult(int n);
double array[102][102];
int main()
{int n,m,k;
double result;
scanf("%d%d",&n,&m);
getarray(n);
showarray(n);
result=getresult(n);
k=(int)result%m;
if(k<0)k+=m;
printf("%ld\n",k);
system("pause");
return 0;
}
void getarray(int n)
{int row,col;
for(row=0;row<n;row++)
{for(col=0;col<n;col++)

scanf("%lf",&array[row][col]);
}
}
void showarray(int n)
{int row,col;}
double getresult(int n)
{double temp,result=1.0;
int switchtime=0,flag=0;
int row,nextrow,col,stemp;
for(row=0;row<n-1;row++)
{nextrow=row+1;
if(array[row][row]==0)
{while(array[nextrow][row]==0)
{nextrow++;

if(nextrow==n){flag=1;break;}
}
if(flag==1) continue;
switchtime++;
for(col=0;col<n;col++)
{stemp=array[row][col];

array[row][col]=array[nextrow][col];

array[nextrow][col]=stemp;
}
}
for(nextrow=row+1;nextrow<n;nextrow++)
{temp=array[nextrow][row]/array[row][row];
for(col=0;col<n;col++)
array[nextrow][col]+=-temp*array[row][col];
}
}
showarray(n);
for(row=0;row<n;row++)
result*=array[row][row];
if(switchtime%2) return -result;
else return result;
}
我的程序大家帮忙看下错误,谢谢了

回复

使用道具 举报

千问 | 2011-5-11 09:14:35 | 显示全部楼层
做acm的题还是要自己调试的好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行