• Codeforces Round #484 (Div. 2) B. Bus of Characters


    Example 1
    input
    2
    3 1
    0011
    output
    2 1 1 2
    
    Example 2
    input
    6
    10 8 9 11 13 5
    010010011101
    output
    6 6 2 3 3 1 4 4 1 2 5 5
    

      

    题目大意:

        公交车有n行,每行有2个座位,每一行的座位大小都为w[i],现在有两种人,第一种会先坐空行的位子,再在空
    行里面选择最大w[i]的位子坐;第二种人则是选择有人坐的一行,在那些行里选择位子w[i]最小的

    分析:

    先将位子按w排序,第一种人选定好后,将他的座位放入队列里,然后第二种人从队列里选择w最小的就行了

    code:

    #define debug
    #include<bits/stdc++.h>
    #define pb push_back
    #define dbg(x) cout<<#x<<" = "<<(x)<<endl;
    #define lson l,m,rt<<1
    #define cmm(x) cout<<"("<<(x)<<")";
    #define rson m+1,r,rt<<1|1
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll>PLL;
    typedef pair<int,ll>Pil;
    const ll INF = 0x3f3f3f3f;
    const ll inf=0x7fffffff;
    const double eps=1e-8;
    const int maxn =1e6+10;
    const int N = 510;
    const ll mod=1e9+7;
    const ll MOD=1e9;
    //------
    //define
    int a[maxn];
    struct node{
    	int id,w;
    	node(int id=0,int w=0):id(id),w(w){}
    	bool operator <(const node &a)const{
    		return w<a.w;
    	}
    }w[maxn]; 
    //solve
    void solve() {
    	int n;
    	while(cin>>n){
    		int cnt_1=0;
    		int cnt_2=n-1;
    		priority_queue<node>q;
    		for(int i=0;i<n;i++){
    			int tmp;
    			cin>>tmp;
    			w[i]=node(i+1,tmp);
    		}
    		sort(w,w+n);
    		for(int i=0;i<2*n;i++){
    			char tt;
    			cin>>tt;
    			int tmp=tt-'0';
    			if(!tmp){
    				a[i]=w[cnt_1].id;
    				q.push(w[cnt_1++]);
    				
    			}else{
    				a[i]=q.top().id;
    				q.pop();
    			}
    		}
    		for(int i=0;i<2*n;i++){
    			cout<<a[i]<<" ";
    		}
    	}
    }
    
    int main() {
    	ios_base::sync_with_stdio(false);
    #ifdef debug
    	freopen("in.txt", "r", stdin);
    //	freopen("out.txt","w",stdout);
    #endif
    	cin.tie(0);
    	cout.tie(0);
    	solve();
    	/*
    		#ifdef debug
    			fclose(stdin);
    			fclose(stdout);
    			system("out.txt");
    		#endif
    	*/
    	return 0;
    }
    

      

  • 相关阅读:
    Matlab编辑器背景修改
    Booksim的运行
    illustrator画梯形
    latex去掉页眉
    latex字体颜色
    latex字体
    Methods to reduce the number of pipeline stages
    Basic Router Architecture
    Linux /sbin/service脚本一个基本无影响的bug
    HTML5实战之桌面通知
  • 原文地址:https://www.cnblogs.com/visualVK/p/9083924.html
Copyright © 2020-2023  润新知