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 lijunyi at 2017-07-21 07:39:02 on Problem 1166
In Reply To:少量测试数据+高斯消元代码 Posted by:15211160230 at 2017-03-31 17:00:08
> 搞了一下午QAQ。
> #include <cstdio>
> #include <memory.h>
> #include <cstring>
> #include <algorithm>
> #define maxn 11
> using namespace std;
> int Map[maxn][maxn],N=9;
> char *line[]={"ABDE","ABC","BCEF","ADG","BDEFH","CFI","DEGH","GHI","EFHI"};
> void Init()
> {	int i,j;
> 	memset(Map,0,sizeof(Map));
> 	for(j=0;j<N;++j)
> 		for(i=0;i<strlen(line[j]);++i)
> 			Map[line[j][i]-'A'][j]=1;
> }
> int Free[maxn],ans[maxn];
> void GaussSolve()
> {	int i,j,k,res=0,r=0;
> 	int x,y;
> 	memset(Free,0,sizeof(Free));
> 	for(i=0;i<N;++i)
> 	{	if(Map[r][i]==0)
> 		{	for(j=r+1;j<N;++j)
> 				if(Map[j][i]>0)
> 				{	for(k=i;k<=N;++k)
> 						swap(Map[r][k],Map[j][k]);
> 					break;
> 				}
> 		}
> 		if(Map[r][i]==0)
> 		{	res++;
> 			continue;
> 		}
> 		for(j=r+1;j<N;++j)
> 		{	if(Map[j][i]>0)
> 			{	x=Map[r][i];
> 				y=Map[j][i];
> 				for(k=i;k<=N;++k)
> 				{	Map[j][k]=Map[j][k]*x-y*Map[r][k];
> 					Map[j][k]=(Map[j][k]%4+4)%4;					
> 				}
> 			}		
> 		}	
> 		Free[i]=1,r++;
> 	}
> 	int temp;
> 	for(i=N-1;i>=0;--i)
> 	{	temp=Map[i][N];
> 		for(j=i+1;j<N;j++)
>             temp-=Map[i][j]*ans[j];
> 		temp=(temp%4+4)%4;
> 		for(ans[i]=0;ans[i]<=3;++ans[i])
> 			if((ans[i]*Map[i][i]%4+4)%4==temp)
> 				break;
> 		ans[i]%=4;
> 	}
> 	bool flag=0;
> 	for(i=0;i<N;++i)
> 		for(j=0;j<ans[i];++j)
> 			printf(flag==0?"%d":" %d",i+1),flag=1;
> 	puts("");
> }
> int main()
> {	int i,w;
> 	Init();
> 	for(i=0;i<N;++i)
> 		scanf("%d",&w),Map[i][N]=(4-w)%4;
> 	GaussSolve();	
> 	return 0;
> }
> /*
> 2 1 3
> 0 1 2
> 3 1 0
> 1 2 2 2 4 4 5 5 5 6 6 7 7 8 9
> 
> 3 3 0
> 2 2 2
> 2 1 2
> 4 5 8 9
> 
> 0 0 0
> 0 0 0
> 0 0 2
> 3 3 5 5 6 6 7 7 8 8 9 9
> */

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