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

大家看看我这哪里错了?

Posted by 843889128 at 2013-04-02 21:04:26
#include <stdio.h>
#include <stdlib.h>

int lengthofLoad, numofArea;
int * start,* end;
void main(int argc, char *argv)
{
	int i = 0;
	int result;

	scanf("%d %d",&lengthofLoad,&numofArea);
	
	if(numofArea <= 0 || lengthofLoad <= 0)
	{
		return;
	}

	start = (int *)malloc(sizeof(int)*numofArea);
	end = (int *)malloc(sizeof(int)*numofArea);

	while(i < numofArea)
	{

		scanf("%d %d",&start[i],&end[i]);
		i++;
	}
	result = NumofTree();
	printf("%d\n",result);
}

int NumofTree()
{
	char *trees = (char*)calloc(lengthofLoad, sizeof(char));
	int i = 0, j = 0;
	for(;i < numofArea; i++)
	{
		j = start[i];
		for(;j <= end[i]; j++)
			trees[j] = '1';
	}
	j = 0;
	for(i = 0; i<lengthofLoad; i++)
		if(trees[i] == '1')
			j++;

	return lengthofLoad - j + 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