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

求解为什么老runtime error!

Posted by woshiliyiyiyiyi at 2013-01-14 10:36:08 on Problem 2528
#include<stdio.h>
#define N 20050
#define L(x) (x<<1)
#define R(x) ((x<<1)+1)
#define Min(a, b) (a > b ? b : a)
#define Max(a, b) (a > b ? a : b)

typedef struct node
{
    int l;
    int r;
    int color;
}Node;

Node value[N];
int map[N][2];
int number[N];
int kk;

void find(int count)
{
    int i;
	
    if (value[count].l == value[count].r)
    {
		for (i=0; i<kk; i++)
			if (number[i] == value[count].color)
			{
				return ;
			}
			if (value[count].color)
			{
				number[kk++] = value[count].color;
			}
			
			return ;
    }
	
    for (i=0; i<kk; i++)
		if (number[i] == value[count].color)
		{
			break ;
		}
		if (value[count].color)
		{
			if (i == kk)
			{
				number[kk++] = value[count].color;
			}
			return ;
		}
		find(L(count));
		find(R(count));
		
		return ;
}

void buildtree(int lift, int right)
{
    Node stack[N];
    int i = -1;
    int mid;
    int a, b, c;
	
    value[1].l = lift;
    value[1].r = right;
    value[1].color = 0;
    stack[++i].l = lift;
    stack[i].r = right;
    stack[i].color = 1;
	
    while (i >= 0)
    {
		a = stack[i].l;
		b = stack[i].r;
		c = stack[i].color;
		
		i--;
		
		if (a != b)
		{
			mid = (a + b) >>1;
			stack[++i].l = a;
			stack[i].r = mid;
			stack[i].color = L(c);
			
			value[L(c)].l = a;
			value[L(c)].r = mid;
			value[L(c)].color = 0;
			
			stack[++i].l = mid + 1;
			stack[i].r = b;
			stack[i].color = R(c);
			
			value[R(c)].l = mid + 1;
			value[R(c)].r = b;
			value[R(c)].color = 0; 
		}
    }
	
    return ;
}


void insert(int color, int lift, int right, int count)
{
    if (value[count].l==lift && value[count].r==right)
    {
		value[count].color = color;
		return ;
    }
	
    if (value[count].color > 0)
    {
		value[L(count)].color = value[count].color;
		value[R(count)].color = value[count].color;
		value[count].color = 0;
    }
	
    if (value[R(count)].l <= lift)
    {
		insert(color, lift, right, R(count));
    }
    else if (value[L(count)].r >= right)
    {
		insert(color, lift, right, L(count));
    }
    else
    {
		insert(color, lift, value[L(count)].r, L(count));
		insert(color, value[R(count)].l, right, R(count));
    }
	
    return ;
}

int main()
{
    int num;
    int i, n;
    int mid, min, max;
	
    fscanf(stdin, "%d", &num);
	
    while (num--)
    {
		kk = 0;
       	min = 100000;
        max = -1;
        fscanf(stdin, "%d", &n);
        for (i=0; i<n; i++)
        {
			fscanf(stdin, "%d %d", map[i]+0, map[i]+1);
			
			mid = Min(map[i][0], map[i][1]);
			if (mid < min)
			{
				min = mid;
			}
			
			mid = Max(map[i][0], map[i][1]);
			if (mid > max)
			{
				max = mid;
			} 
        }
		
       	buildtree(min, max);
        for (i=0; i<n; i++)
        {
			insert(i+1, map[i][0], map[i][1], 1);
        }
		find(1);
        printf("%d\n", kk);
    }
	
    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