Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:不知道为什么大家写的代码都那么长?提供下我写的·。

Posted by zms1515 at 2022-04-03 14:54:00 on Problem 3233
In Reply To:不知道为什么大家写的代码都那么长?提供下我写的·。 Posted by:tcet030840zxp at 2012-03-11 00:14:40
> #include<stdio.h>
> #include<string.h>
> int b[65][65],x[65][65];
> int n,k,m;
> void mul(int a[65][65],int x[65][65])
> {
> 	int i,j,k;
> 	int t[65][65];
> 	memset(t,0,sizeof(t));
> 	for(i=0;i<n;i++)
> 		for(j=0;j<n;j++)
> 			for(k=0;k<n;k++)
> 				t[i][j]=(t[i][j]+a[i][k]*x[k][j])%m;
> 	memcpy(a,t,sizeof(t));
> }
> int main()
> {
> 	int i,j;
> 	scanf("%d%d%d",&n,&k,&m);
> 	for(i=0;i<n;i++)
> 		for(j=0;j<n;j++)
> 			scanf("%d",&x[i][j]);
> 	for(i=0;i<n;i++)
> 	{
> 		x[i+n][i]=1;
> 		x[i+n][i+n]=1;
> 		b[i][i]=1;
> 		b[i][i+n]=1;
> 	}
> 	n<<=1;
> 	for(i=0;(1<<i)<=k;i++)
> 	{
> 		if(k&(1<<i))mul(b,x);
> 		mul(x,x);
> 	}
> 	n>>=1;
> 	for(i=0;i<n;i++)b[i][i]=(b[i][i]-1+m)%m;
> 	for(i=0;i<n;i++)
> 	{
> 		for(j=0;j<n-1;j++)printf("%d ",b[i][j]);
> 		printf("%d\n",b[i][n-1]);
> 	}
> 	return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator