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:USACO,chapter 1

Posted by tzkq at 2010-06-19 17:41:32 on Problem 1166 and last updated at 2010-06-19 18:02:33
In Reply To:USACO,chapter 1 Posted by:tzkq at 2010-06-19 16:29:36
写了一个,还好,通过了。
再仔细想想,用矩阵来做有什么好处呢? 可以处理更强的数据,当模量为40的时候,效率一样,只是求解的参数不同,矩阵的本质和高斯消元相同,使用起来更抽象。
int i,k,v[9],A[9],I[][9]={
{ -1,  3, -1,  3, -1, -2, -1, -2,  4},
{  2, -1,  2, -1,  2, -1, -3,  4, -3},
{ -1,  3, -1, -2, -1,  3,  4, -2, -1},
{  2, -1, -3, -1,  2,  4,  2, -1, -3},
{  2, -1,  2, -1, -3, -1,  2, -1,  2},
{ -3, -1,  2,  4,  2, -1, -3, -1,  2},
{ -1, -2,  4,  3, -1, -2, -1,  3, -1},
{ -3,  4, -3, -1,  2, -1,  2, -1,  2},
{  4, -2, -1, -2, -1,  3, -1,  3, -1}},

T[]={4, 8, 4, 8, 4, 8, 4, 8, 4};//a'解

int main(){
	for(i=0;i<9;i++){
		scanf("%d",&k);
		v[i]=(4-k)%4;
	}
	for(i=0;i<9;i++)for(k=0;k<9;k++)A[i]+=v[k]*I[k][i];//矩阵乘法

	while(1){//寻找整数解
		for(i=0;i<9&&0<=A[i]&&A[i]%5==0;i++);
		if(i==9)break;
		for(i=0;i<9;i++)A[i]+=T[i];
	}
	for(i=0;i<9;i++)for(k=A[i]/5%4;k--;)printf("%d ",i+1);
}


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