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

求助JAVA类变量初始化。。。

Posted by kf at 2008-01-05 18:41:06 on Problem 3476
主函数跑到第一个for就挂了,咋回事捏?
import java.util.*;
class Main{
    static class Heap{
	int HeapSize,index[]=new int[1000010];
	class W
	{
	    char c;
	    int next,ldp,ldn,ed;
	};
	W []d=new W[1000010];
	class WW
	{
	    int sum,place;
	};
	boolean cmp(Heap.WW A,Heap.WW B)
	{
	    return A.sum>B.sum||A.sum==B.sum&&A.place<B.place;
	}
	WW []Heap=new WW[1000010];
	void HeapUp(int p)
	{
	    int q=p>>1;
	    WW a=Heap[p];
	    while(q!=0)
	    {
		if(cmp(a,Heap[q]))
		{
		    Heap[p]=Heap[q];
		    index[Heap[p].place]=p;
		}
		else break;
		p=q;
		q=p>>1;
	    }
	    Heap[p]=a;
	    index[Heap[p].place]=p;
	}
	void AddToHeap(WW a)
	{
	    Heap[++HeapSize]=a;
	    HeapUp(HeapSize);
	}
	void HeapDown(int p)
	{
	    int q=p<<1;
	    WW a=Heap[p];
	    while(q<=HeapSize)
	    {
		if(q<HeapSize&&cmp(Heap[q+1],Heap[q]))q++;
		if(cmp(Heap[q],a))
		{
		    Heap[p]=Heap[q];
		    index[Heap[p].place]=p;
		}
		else break;
		p=q;
		q=p<<1;
	    }
	    Heap[p]=a;
	    index[Heap[p].place]=p;
	}
	int GetTopFromHeap()
	{
	    int TopElement=Heap[1].place;
	    Heap[1]=Heap[HeapSize--];
	    HeapDown(1);
	    return TopElement ;
	}
	void BuildHeap () // Remember to Let HeapSize = N
	{
	    for(int i=HeapSize;i>0;i--)
		HeapDown(i);
	}
    };
    public static void main(String args[])
    {
	Heap H=new Heap();
	int i,head,bg,qt,ht,ps;
	Scanner cin=new Scanner(System.in);
	String t=new String("1"),s=cin.next();
	t+=s;
	for(i=1;i<t.length();i++)
	    H.d[i].c=t.charAt(i);
	for(head=0,i=1;i<t.length();i++)
	    if(t.charAt(i)==t.charAt(i-1))
	    {
	        H.d[i-1].next=i;
	        H.Heap[H.HeapSize].sum++;
	    }
	    else
	    {
		H.d[head].ed=i-1;
		H.d[head].ldn=i;
	        H.d[i].ldp=head;
	        head=i;
	        H.Heap[++H.HeapSize].place=i;
	        H.Heap[H.HeapSize].sum=1;
	        H.index[i]=H.HeapSize;
	    }
	H.d[head].ed=i-1;
	H.BuildHeap();
        while(H.HeapSize>0&&H.Heap[1].sum>1)
        {
	    i=bg=H.GetTopFromHeap();
	    System.out.print(H.d[bg].c);
	    for(;H.d[i].next!=0;i=H.d[i].next)
	    System.out.print(' '+i);
	    System.out.println(' '+i);
	    qt=H.d[bg].ldp;
	    ht=H.d[bg].ldn;
	    H.d[qt].ldn=ht;
	    H.d[ht].ldp=qt;
	    if(H.d[qt].c==H.d[ht].c)
	    {
	        H.d[H.d[qt].ed].next=ht;
	        H.d[qt].ed=H.d[ht].ed;
	        H.d[qt].ldn=H.d[ht].ldn;
	        H.d[H.d[ht].ldn].ldp=qt;
	        H.Heap[H.index[qt]].sum+=H.Heap[H.index[ht]].sum;
	        H.HeapUp(H.index[qt]);
	        H.index[H.Heap[H.HeapSize].place]=H.index[ht];
	        H.Heap[H.index[ht]]=H.Heap[H.HeapSize--];
	        ps=H.Heap[H.index[ht]].place;
	        H.HeapUp(H.index[ps]);
	        H.HeapDown(H.index[ps]);
	    }
	}
    }
}

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