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

my ugly code

Posted by qq312873977 at 2009-04-29 19:31:10 on Problem 1972
#include<iostream>
using namespace std;
int diceNum[10001][7];
int findopposite(int i)
{
	switch(i)
	{
	case 1:return 6;
	case 2:return 4;
	case 3:return 5;
	case 4:return 2;
	case 5:return 3;
	case 6:return 1;
	}
	return -1;
}
int findMax(int didx,int up)
{
	int opp=findopposite(up);
	int maxnum=0;
	int i=0;
	while(i<=5)
	{
		i++;
		if(i==up||i==opp)
			continue;
		if(diceNum[didx][i]>maxnum)
			maxnum=diceNum[didx][i];
	}
	return maxnum;
}
int main()
{
	int t,dnum,i,j,down,up,sum,maxsum,k;
	cin>>t;
	while(t--)
	{
		cin>>dnum;
		maxsum=0;
		for(i=1;i<=dnum;i++)
			for(j=1;j<=6;j++)
				cin>>diceNum[i][j];
		for(i=1;i<=6;i++)
		{
			sum=0;
			up=diceNum[1][i];
			sum+=findMax(1,i);
			for(j=2;j<=dnum;j++)
			{
				for(k=1;k<=6;k++)
					if(diceNum[j][k]==up)
						break;
				up=diceNum[j][findopposite(k)];
				sum+=findMax(j,k);
			}
			if(sum>maxsum)
				maxsum=sum;
		}
		cout<<maxsum<<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