| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
急救??Source Code
Problem: 1089 User: harith
Memory: N/A Time: N/A
Language: C++ Result: Memory Limit Exceeded
那位大侠帮帮忙??
Source Code
#include<iostream>
using namespace std;
int temp;
template<class T>class list;
template<class T>
class node
{
friend class list<T>;
private:
T data1;
T data2;
node<T> *next;
};
template <class T>
class list
{
public:
list(){first=0;}
void input (int n);
void output();
void bin_sort(int m);
void haibao();
private:
node<T> *first;
};
template <class T>
void list<T>::input(int n)
{
int i;
node<int> *np,*p,*q;
node<int> *h;
int temp1=0;
for(i=0;i<n;i++)
{
np=new node<int>;
cin>>np->data1>>np->data2;
if(np->data1>=temp1)temp1=np->data1;
if(first==0)
{
first=np;
h=np;
h->next=0;
}
else
{
h->next=np;
np->next=0;
h=np;
}
}
temp=temp1;
}
template<class T>
void list<T>::output()
{
node<int> *h;
for(h=first;h;h=h->next)
{
cout<<h->data1<<" "<<h->data2;
cout<<endl;
}
}
template<class T>
void list<T>::bin_sort(int m)
{
int b;
node<int>**bottom,**top;
bottom=new node<int> *[m+1];
top=new node<int>*[m+1];
for(b=0;b<=m;b++)
bottom[b]=0;
for(;first;first=first->next)
{
b=first->data1;
if(bottom[b])
{
top[b]->next=first;
top[b]=first;
}
else
bottom[b]=top[b]=first;
}
node<int>*p=0;
for(b=0;b<=m;b++)
if(bottom[b])
{
if(p)p->next=bottom[b];
else first=bottom[b];
p=top[b];
}
if(p)p->next=0;
delete[]bottom;
delete[]top;
}
template<class T>
void list<T>::haibao()
{
node<int>*h,*p,*q;
h=first;
p=h->next;
while(p!=0)
{
if(p->data1<=h->data2)
{
if(p->data2>=h->data2)
{
h->data2=p->data2;
if(h->data1<=p->data1) ;
else if(h->data1>p->data1) h->data1=p->data1;
q=p;
h->next=p->next;
p=p->next;
delete q;
}
else
{
if(h->data1<=p->data1) ;
else if(h->data1>p->data1) h->data1=p->data1;
q=p;
h->next=p->next;
p=p->next;
delete q;
}
}
else
{
h=h->next;
p=p->next;
}
}
}
int main()
{
int n;
list<int> ad;
cin>>n;
ad.input(n);
ad.bin_sort(temp);
ad.haibao();
ad.output();
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator