zoukankan      html  css  js  c++  java
  • 集合字典序(优先队列)

    题目链接 :传送门
     
    解题思路:我们可以维护两个小顶堆的优先队列,然后每次入队的时候,对队列前面的元素进行比较,如果相等就一直pop,否则,就跳出循环,然后比较一下两个队列的前端,如果第一个队列大则输出>,反之输出<,如果队列为空,则输出=
     
    Code:

    #include<bits/stdc++.h>
    using namespace std;
    
    int n,a,b;
    priority_queue<int,vector<int>,greater<int> > que1,que2;
    
    int main()
    {
    	while(~scanf("%d",&n)) {
    		for(int i = 0;i < n; ++i) {
    			scanf("%d%d",&a,&b);
    			que1.push(a);
    			que2.push(b);
    			int op = 0;
    			while(que1.size()) {
    				if(que1.top() == que2.top()) {
    					que1.pop();
    					que2.pop();
    				}
    				else {
    					if(que1.top() > que2.top()) {
    						op = 1;
    					}
    					else {
    						op = -1;
    					}
    					break;
    				}
    			}
    			if(op == 0) {
    				puts("=");
    			}
    			else if(op == 1) {
    				puts(">");
    			}
    			else if(op == -1) {
    				puts("<");
    			}
    		}
    		while(que1.size()) {
    			que1.pop();
    			que2.pop();
    		}
    	}
    	
    	return 0;
    }
    
  • 相关阅读:
    oracle 更改账户名密码
    mongodb 分片副本集搭建
    爬虫目录
    centos MySQL安装与卸载
    ANACONDA 安装
    chrome 安装
    linux pycharm 安装 idea
    linux 基本命令
    高数18讲 之极限与连续
    高数18讲 之基础知识
  • 原文地址:https://www.cnblogs.com/Mangata/p/14294672.html
Copyright © 2011-2022 走看看