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

Question about 1050 & 1207

Posted by downstair at 2012-03-26 06:16:36
Hello, 
I am a fresh C programmer. I just try to do several problems in the database. I am confused of the result of the judge because I got the right answer from my VC 6.0 compiler. But the judge turns wrong answer. I have no idea what the reason is. Could you please tell me the problems? Thank you.



Problem 1050
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int n;
	int **data;
	int i,j,k,l;
	long sum1,sum2,sum3,sum4;
	long max1, max2, max;

	scanf("%d\n",&n);

	data = (int**) malloc(sizeof(int*) * n);
	for( i = 0; i < n; i++)
	{
		*(data+i) = (int*) malloc(sizeof(int) * n);
	}
	

	for( i = 0; i < n; i++)
	{
		for(j = 0; j < n; j++)
		{
			scanf("%d", *(data+i)+j);
		}
	}

	sum1 = sum2 = sum3 = sum4 = 0;
	max = max1 = max2 = 0;

	for ( i = 0; i < n; i++)
	{
		for(j = 0; j < n; j++)
		{

			for( k = 0; k < n; k++)
			{
				for( l = 0; l < n; l++)
				{
					if( k<=i && l<=j)
					{
						sum1 += data[k][l];
					}
					if( k<=i && l>j)
					{
						sum2 += data[k][l];
					}
					if( k>i && l<=j)
					{
						sum3 += data[k][l];

					}
					if( k>i && l>j)
					{
						sum4 += data[k][l];

					}
				}
			}

				if( sum1 >= sum2 ) 
				{
					max1 = sum1;
				}
				else if( sum1 < sum2 ) 
				{
					max1 = sum2;
				}
				if( sum3 >= sum4 )
				{
					max2 = sum3;
				}
				else if( sum3 < sum4 )
				{
					max2 = sum4;
				}

				if(max1 >= max2 && max1 >= max) { max = max1;}
				else if(max1 < max2 && max2 >= max) {max = max2;}

			sum1 = sum2 = sum3 = sum4 = 0;

		}
		
	}
	printf("%ld\n", max);

	return 0;
}


Problem 1207

#include <stdio.h>

int count;
int fun(int index);
void main_11(int i, int j);



int main(void)
{
	int k;
	int line = 0;
	int d[100][2];
	k = 1;
	while( k == 1)
	{

		if( scanf("%d %d", &d[line][0], &d[line][1]) == 2 )
		{
			line += 1;
		}
		else 
			k = 0;
	}

	while( k < line )
	{
		main_11(d[k][0],d[k][1]);
		k = k + 1;
	}

	return 0;
}
		


void main_11(int i, int j)
{
	int input;
	int cycle;
	int max = 0;
	extern int count;

	for( input = i; input <= j; input++)
	{
		count = 0;
		cycle =	fun(input);
		if( cycle >= max )
		{
			max = cycle;
		}
	}

	printf("%d %d %d\n", i, j , max);
}


int fun(int index)
{
	extern int count;
		if(index == 1)
		{
			count += 1;
			return count;
		}
		if( index%2 == 0 )
		{
			index = index/2;
		}
		else if( index%2 != 0 )
		{
			index = index*3 + 1;
		}
		count += 1;
		fun(index);
}



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