没写完的代码先搁着

#include <iostream>
using namespace std;
struct Task{
    int ID;//任务编号
    int key;//任务优先级
    int load;//任务持续时间
    Task *next;
};
Task* getBatch(int count)
{int i,key1;
    Task *head,*p,*q;cin>>key1;
    head=new Task;
    cin>>head->ID>>head->load;head->key=key1;
    head->next=NULL;q=head;
    for(i=0;i<count-1;i++)
    {
    	p=new Task;
    	cin>>p->ID>>p->load;
    	p->key=key1;
    	q->next=p;
    	q=p;
	}
	return head;
}
Task* addBatch(Task *head, Task *h)
{
	Task *p,*q1,*q;
	p=head;q=h;q1=head;
	for(;q->next!=NULL;q=q->next);
	for(;p->next!=NULL;p=p->next)
	{
		if(h->key<head->key)//插入在头部 
		{
			q->next=head;return q1;
		} 
		if(p->key<=h->key&&p->next->key>=h->key)//插入在中间 
		{
			q->next=p->next;
			p->next=q1;
			return head;
		}
	}
	if(p->key<=h->key)
	{
		p->next=q1;return head;
	}
}
void display(Task *head, int m)
{
	Task *p,*p1;
	int i=0,j;
	for(p=head;p->next!=NULL;p=p->next)
	{
		i++;
	}
	if(i<m)
	{
		cout<<"OK"<<endl;
	}
	else if(i>=m)
	{
		for(j=0,p=head;j<m;p=p->next);
		cout<<p->ID<<" "<<p->key<<" "<<p->load<<endl; 
	}
}
Task* study(Task*head, int mi, int ma, int load)
{
	Task *p,*p1,*p2;
	p=p1=p2=head;
	for(;p->next!=NULL;p=p->next);
	while(p2->next!=NULL&&load>0)//结点的删除 全部一起考虑 
	{
		if(p2==head)
		{
			if(p2->load<=ma&&p2->load>=mi)
			{
				if(load-p2->load>=0) load-=p2->load;
				p1=p1->next;delete head;
			}
		}
		else
		{
			if(p2->next->load<=ma&&p2->next->load>=mi)
			{
				if(load-p2->next->load>=0)
				{ load-=p2->next->load;
				Task *q;
			    q=p2->next;
			    p2->next=p2->next->next; delete q;
			    }
			}
		}
		p2=p2->next;
	}
	return p1;
}
void del(Task* head){//删除链表
    if(head==NULL) return;
    del(head->next);
    delete head;
}
const int K=3;//幸运数字
int main(){
    int count, mi, ma, load;
    Task *head=NULL, *h;
    cin>>count;//输入行的第一个数字
    while(count!=0){
        if(count>0){   //新添加count个任务
            h=getBatch(count);//构建链表,并将首指针返回给h
            display(h, K);//显示小链表的第K个任务或输出OK
            head=addBatch(head, h);//将小链表加入大链表,并将首指针返回
        }else{
            cin>>mi>>ma>>load;
            head=study(head, mi, ma, load);
            display(head,K);//显示大链表的第K个任务或输出OK
        }
        cin>>count;		
    }
    del(head);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值