当前位置: 首页 > wzjs >正文

北京清控人居建设集团网站云浮市住房和城乡建设局网站

北京清控人居建设集团网站,云浮市住房和城乡建设局网站,网站营销教程,可以下载app的软件文章目录 栈题目解析代码 优先级队列题解代码 map题解代码 set题解代码 栈 题目解析 1.先把元素push进栈中&#xff0c;如果栈非空并且栈中的元素按顺序和k相等就出栈&#xff0c;直到栈为空或者k ! sk.top() 代码 #include<iostream> #include<stack> #include&l…

文章目录

    • 题目解析
    • 代码
  • 优先级队列
    • 题解
    • 代码
  • map
    • 题解
    • 代码
  • set
    • 题解
    • 代码

在这里插入图片描述

题目解析

1.先把元素push进栈中,如果栈非空并且栈中的元素按顺序和k相等就出栈,直到栈为空或者k != sk.top()

代码

#include<iostream>
#include<stack>
#include<vector>
using namespace std;int main()
{stack<int> sk;int n = 0;cin >> n;vector<int> v(n);for (int i = 0; i < n; i++) cin >> v[i];int k = 1;for (int i = 0; i < n; i++){sk.push(v[i]);while(!sk.empty()&&k == sk.top()){sk.pop();k++;}}if (sk.empty()){cout << "Yes" << '\n';}else{cout << "No" << '\n';}return 0;
}

优先级队列

在这里插入图片描述

题解

1. 用sum统计篮子的重量
2. 是1就push,增加sum
3. 是2就减少sum,pop,并且要判空,非空才能减,不然优先级对列会报错

代码

#include<iostream>
#include<stack>
#include<vector>
#include<queue>
using namespace std;const int N = 1e5 + 10;
using ll = long long;
int main()
{int q;cin >> q;priority_queue<ll> pq;ll sum = 0;while(q--){int x = 0;cin >> x;if(x == 1){int y;cin >> y;pq.push(y);sum += y;}else if( x == 2){if(!pq.empty()) {sum -= pq.top();pq.pop();}}}cout << sum;return 0;
}

map

在这里插入图片描述

题解

1. map统计字符串出现的次数
2. vector可以把字符串按顺序输出
3. 第一次出现就插入到vector中

代码

#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;const int N = 1e5 + 10;
using ll = long long;void slove()
{int n;cin >> n;map<string,int> p;// map是有序的vector<string> v;// 表示字符串出现的顺序for(int i = 0;i < n;i++){string s; cin >> s;if(p.count(s)) p[s]++;else {v.push_back(s);p[s] = 1;}}for(auto& x : v)cout << x << " " << p[x] << '\n';
}
int main()
{int t = 0;cin >> t;while(t--)slove();return 0;
}

set

在这里插入图片描述

题解

1. 把数插入到set中,set会自动帮我们排好序的,然后输出就行了

代码

#include<iostream>
#include<vector>
#include<set>
#include<algorithm>using namespace std;int main()
{int n;cin >> n;set<int> st;for(int i = 0;i < n;i++){int x;cin >> x;st.insert(x);}for(auto x : st) cout << x << " ";return 0;
}

文章转载自:

http://RPg4Gug5.gyfzp.cn
http://sjjGQMwq.gyfzp.cn
http://GCZ2PdTr.gyfzp.cn
http://cbVC5dnE.gyfzp.cn
http://7tLzWAVP.gyfzp.cn
http://wnk8ez6m.gyfzp.cn
http://Ex7Og8sb.gyfzp.cn
http://H9tY3gHH.gyfzp.cn
http://L1l94djx.gyfzp.cn
http://C0RXFRei.gyfzp.cn
http://NW1WUSqn.gyfzp.cn
http://K89uneV4.gyfzp.cn
http://QrLqBCHt.gyfzp.cn
http://vixjrGht.gyfzp.cn
http://pNe7hY1I.gyfzp.cn
http://JWTdyqhK.gyfzp.cn
http://BHekO6ZW.gyfzp.cn
http://1THmSIB8.gyfzp.cn
http://fC8ZrfaN.gyfzp.cn
http://P1MusIP3.gyfzp.cn
http://kr6eixGV.gyfzp.cn
http://qK00kUSX.gyfzp.cn
http://R4iRJJEc.gyfzp.cn
http://eUN8cyRP.gyfzp.cn
http://z9EaTsah.gyfzp.cn
http://fDrQRGMc.gyfzp.cn
http://Fc8dyI5v.gyfzp.cn
http://qy9aLfGt.gyfzp.cn
http://aMnBfZFW.gyfzp.cn
http://g93nkgpk.gyfzp.cn
http://www.dtcms.com/wzjs/681407.html

相关文章:

  • 网站制作公司 沈阳网站制作制作网站建网站
  • 河北邯郸网站建设好用的h5网站模板下载
  • 做网站怎么接单盐城网站建设
  • 学习做网站wordpress侧栏显示指定分类
  • 网站模版 带 手机版ps个人网站
  • 搭建个人网站教程培训机构排名一览表
  • 展会网站怎么做北京市网站开发
  • wordpress搬运搜索引擎优化的作用是什么
  • 青岛会议网站制作公司高端网站建设有哪些
  • 雅虎做网站推广百度官网首页下载
  • 英文网站制作 官网专门做网站的科技公司
  • 电商网站设计流程图网站的服务器在哪里
  • 电脑网站与手机的区别衡水网站设计公司哪家好
  • 郑州网站建设公司有哪些安庆市建设工程造价信息网
  • 捕鱼游戏在哪做网站做360手机网站快速排名软件
  • 辽宁省城乡建设网站西宁网站建设模板
  • 卖域名的网站哪些好wordpress网站访问量
  • 不正规网站制作品牌网站建设預定大蝌蚪
  • 网站建站平台公司交易网站开发
  • 网站改版阿里云怎么做网站301定向上海app开发
  • 怎么建设网站网页游戏水源logo设计制作网
  • 网站好坏标准自己做的网站 kindle
  • 纯静态网站挂马地方旅游网站建设方案
  • 导视设计网站哪个网站专门做快餐车
  • 十大免费cms建站系统介绍网站模块源码
  • 设计一个公司网站多少钱海港经济开发区人才网
  • 网站 建设需求嘉兴seo外包
  • 中国风网站建设一个服务器怎么做两个网站
  • 网站模版网设计常用的几个软件
  • 网站图标怎么做可以做策略回测的网站