zoukankan      html  css  js  c++  java
  • G

    看病要排队这个是地球人都知道的常识。
    不过经过细心的0068的观察,他发现了医院里排队还是有讲究的。0068所去的医院有三个医生(汗,这么少)同时看病。而看病的人病情有轻重,所以不能根据简单的先来先服务的原则。所以医院对每种病情规定了10种不同的优先级。级别为10的优先权最高,级别为1的优先权最低。医生在看病时,则会在他的队伍里面选择一个优先权最高的人进行诊治。如果遇到两个优先权一样的病人的话,则选择最早来排队的病人。

    现在就请你帮助医院模拟这个看病过程。

    Input

    输入数据包含多组测试,请处理到文件结束。
    每组数据第一行有一个正整数N(0<N<2000)表示发生事件的数目。
    接下来有N行分别表示发生的事件。
    一共有两种事件:
    1:"IN A B",表示有一个拥有优先级B的病人要求医生A诊治。(0<A<=3,0<B<=10)
    2:"OUT A",表示医生A进行了一次诊治,诊治完毕后,病人出院。(0<A<=3)

    Output

    对于每个"OUT A"事件,请在一行里面输出被诊治人的编号ID。如果该事件时无病人需要诊治,则输出"EMPTY"。
    诊治人的编号ID的定义为:在一组测试中,"IN A B"事件发生第K次时,进来的病人ID即为K。从1开始编号。

    Sample Input

    7
    IN 1 1
    IN 1 2
    OUT 1
    OUT 2
    IN 2 1
    OUT 2
    OUT 1
    2
    IN 1 1
    OUT 1

    Sample Output

    2
    EMPTY
    3
    1
    1

    用3个vector存一下,需要的时候排个队,输出第一个编号就好了

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<queue>
    //#include<map>
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=a;i>=n;i--)
    typedef long long ll;
    typedef long double ld;
    typedef double db;
    const ll mod=1e9+100;
    const db e=exp(1);
    using namespace std;
    const double pi=acos(-1.0);
    struct PP
    {
    	int lev,num;
    	PP(){}
    };
    bool cmp(PP a,PP b)
    {
    	if(a.lev==b.lev)
    		return a.num<b.num;
    	return a.lev>b.lev;
    }
    vector<PP>A;
    vector<PP>C;
    vector<PP>B;
    void SHURU(int x,int y,int n)
    {
    	PP t;t.lev=y;t.num=n;
    	if(x==1)		A.push_back(t); 	
    	else if(x==2)	B.push_back(t);
    	else			C.push_back(t);
    }
    void SHUCHU(int x)
    {
    	PP t;
    	if(x==1)
    	{
    		if(A.empty()) pf("EMPTY
    ");
    		else
    		{
    			sort(A.begin(),A.end(),cmp);
    			t=A.front();
    			A.erase(A.begin());
    			pf("%d
    ",t.num); 
    		}
    	}else if(x==2)
    	{
    		if(B.empty()) pf("EMPTY
    ");
    		else
    		{
    			sort(B.begin(),B.end(),cmp);
    			t=B.front();
    			B.erase(B.begin());
    			pf("%d
    ",t.num); 
    		}
    	}else
    	{
    		if(C.empty()) pf("EMPTY
    ");
    		else
    		{
    			sort(C.begin(),C.end(),cmp);
    			t=C.front();
    			C.erase(C.begin());
    			pf("%d
    ",t.num); 
    		}
    	}
    }
    int main()
    {
    	int n;
    	while(~sf("%d",&n))
    	{
    		A.clear();B.clear();C.clear();
    		int bits=1,x,y;
    		char op[5]; 
    		while(n--)
    		{
    			sf("%s",op);
    			if(op[0]=='I')
    			{
    				sf("%d%d",&x,&y);
    				SHURU(x,y,bits++);
    			}else
    			{
    				sf("%d",&x);
    				SHUCHU(x);
    			}
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    gitee之部署vue项目dist目录
    arcgis js 之 featureLayer创建模板
    arcgis js 之featureLayer服务查询及筛选
    video.js视频播放
    vue之监听对象、对象数组的改变
    Element-ui组件库Table表格导出Excel文件
    sublime 常用插件
    前端工具
    css 待处理
    移动前端开发:待处理
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9405071.html
Copyright © 2011-2022 走看看