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

why wa

Posted by onandon at 2008-01-21 16:11:01 on Problem 1166
#include <iostream.h>

#include<stdio.h>
int clocks[9];
			  //  A B C D E F G H I
int moves[9][9]={ 1,1,0,1,1,0,0,0,0,
                  1,1,1,0,0,0,0,0,0,
                  0,1,1,0,1,1,0,0,0,
				  1,0,0,1,0,0,1,0,0,
				  0,1,0,1,1,1,0,1,0,
				  0,0,1,0,0,1,0,0,1,
                  0,0,0,1,1,0,1,1,0,
                  0,0,0,0,0,0,1,1,1,
                  0,0,0,0,1,1,0,1,1     };
int moveUsed[9];
int ret[9];
int main()
{
	int i,j;

//	freopen("1.txt","r",stdin);
	for(i=0;i<9;i++)
		cin>>clocks[i];
	unsigned long tmp,min = 4000000000;

		for(moveUsed[0]=0; moveUsed[0]<=3; moveUsed[0]++)
		for(moveUsed[1]=0; moveUsed[1]<=3; moveUsed[1]++)
		for(moveUsed[2]=0; moveUsed[2]<=3; moveUsed[2]++)
		for(moveUsed[3]=0; moveUsed[3]<=3; moveUsed[3]++)
		for(moveUsed[4]=0; moveUsed[4]<=3; moveUsed[4]++)
		for(moveUsed[5]=0; moveUsed[5]<=3; moveUsed[5]++)
		for(moveUsed[6]=0; moveUsed[6]<=3; moveUsed[6]++)
		for(moveUsed[7]=0; moveUsed[7]<=3; moveUsed[7]++)
		for(moveUsed[8]=0; moveUsed[8]<=3; moveUsed[8]++)
		{
			for(i=0;i<9;i++)
			{ // for each clock, check whether it is 12 o'clock	
				int tmpC=clocks[i];
				for(j=0;j<9;j++)
					tmpC +=moveUsed[j]*moves[j][i];
				if(tmpC % 4 != 0)
					break;
			}
			if(i==9)
			{ // check whether the new setting of moves is the smallest
				tmp=0;
				for(j=0;j<9;j++)
					if(moveUsed[j]!=0)
						tmp++;
					if(tmp<min)
					{
						min = tmp;
						for(j=0;j<9;j++)
							ret[j] = moveUsed[j];
					}
			}
		}
		int flag=0;
		for(i=0;i<9;i++)
		{
			if(ret[i]!=0)
			{
				flag=1;
				cout<<i+1<<' ';
			}
		}
		if(flag==0)
			cout<<'0';
		cout<<endl;
	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