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

门户网站兴化建设局无锡网站程序

门户网站兴化建设局,无锡网站程序,永久免费可联网的进销存软件,网站界面设计需求【题目来源】https://www.lanqiao.cn/problems/3255/learning/【题目描述】给定按从小到大的顺序排列的数字 1 到 n,随后对它们进行 m 次操作,每次将一个数字 x 移动到数字 y 之前或之后。请输出完成这 m 次操作后它们的顺序。【输入格式】第一行为两个数…

【题目来源】
https://www.lanqiao.cn/problems/3255/learning/

【题目描述】
给定按从小到大的顺序排列的数字 1 到 n,随后对它们进行 m 次操作,每次将一个数字 x 移动到数字 y 之前或之后。请输出完成这 m 次操作后它们的顺序。

【输入格式】
第一行为两个数字 n, m,表示初始状态为 1 到 n 的从小到大排列,后续有 m 次操作。
第二行到第 m+1 行,每行三个数 x, y, z。当 z=0 时,将 x 移动到 y 之后;当 z=1 时,将 x 移动到 y 之前。


【输出格式】
一行,n 个数字,中间用空格隔开,表示 m 次操作完成后的排列顺序。

【输入样例】
5 3
3 1 0
5 2 1
2 1 1

【输出样例】
2 1 3 5 4

【算法分析】
★ 在大多数情况下,可以直接使用 C++ 中的 STL list,而不需手写链表。通过这种方式完成的代码通常更简洁。本例代码中将会使用 list<int>::iterator it=find(ls.begin(),ls.end(),y); 得到 y 的位置。

★ STL list:https://cplusplus.com/reference/list/
(1)
size():Returns the number of elements in the list container.
(2)
empty():Returns whether the list container is empty (i.e. whether its size is 0).
(3)
push_front():Inserts a new element at the beginning of the list, right before its current first element. 
(4)
push_back():Adds a new element at the end of the list container, after its current last element. 
(5)
pop_front():Removes the first element in the list container, effectively reducing its size by one. 
(6)
pop_back():Removes the last element in the list container, effectively reducing the container size by one.
(7)
front():Returns a reference to the first element in the list container.
(8)
back():Returns a reference to the last element in the list container.
(9)
reverse():Reverses the order of the elements in the list container.
(10)
insert():The container is extended by inserting new elements before the element at the specified position.
(11)
erase():Removes from the list container either a single element (position) or a range of elements ([first,last)).
(12)
unique():Notice that an element is only removed from the list container if it compares equal to the element immediately preceding it. Thus, this function is especially useful for sorted lists.

【算法代码】

#include <bits/stdc++.h>
using namespace std;int main() {int n,m;cin>>n>>m;list<int> ls;for(int i=1; i<=n; i++) {ls.push_back(i);}while(m--) {int x,y,z;cin>>x>>y>>z;ls.remove(x);list<int>::iterator it=find(ls.begin(),ls.end(),y);if(z==0) ls.insert(++it,x);if(z==1) ls.insert(it,x);}for(auto i:ls) cout<<i<<" ";cout<<endl;return 0;
}/*
in:
5 3
3 1 0
5 2 1
2 1 1out:
2 1 3 5 4
*/



【参考文献】
https://blog.csdn.net/mc10141222/article/details/123674677
https://cplusplus.com/reference/list/list/



 

http://www.yayakq.cn/news/102448/

相关文章:

  • 个人网站备案 内容一个域名下多个网站
  • 如何快速进行网站开发wordpress建站系统
  • 给企业开发网站建设网站的费用入什么科目
  • 沈阳市住房和城乡建设局网站首页旅游网站规划建设
  • 网站设计就业学做网站论坛会员怎么样
  • 网站设计重要性免费行情软件下载入口
  • 一个网站主页开发费用申请域名的方法和流程
  • 温州网站建设温州网站制作wordpress 卡密销售
  • 西安做推广网站设计seo的主要内容
  • 网站建设作用图片雄安移动网上营业厅
  • 网站建设资源kindle上国外网站 dns
  • html静态网站开发实验最主流的网页制作软件
  • 在哪个网站可以自助建站下面哪些属于免费的网络营销方式
  • 深圳西乡网站制作建网站收费吗
  • pc网站建设怎么做大连网络营销咨询服务
  • 做网站建设需要做哪些工作上海市网站制作
  • 中移建设 网站网络服务协议书
  • 扁平化颜色网站城乡建设网站首页
  • 哪家公司的网站做得好民治网站设计圳网站建设公司
  • html网页设计网站开发报告个人博客内容
  • 网页网站设计培训班seo做网站赚钱
  • 什邡网站建设公司网站制作教程dw
  • 网站推广什么意思公司建设网站的公司
  • seo建站营销wordpress登陆页面模板下载
  • 建设网站要多久到账建信建设投资有限公司网站
  • 做简单网站的框架如何建立自己的网站步骤
  • 哪个网站可以付费做淘宝推广通过电子邮件发布 wordpress
  • 能进网站的浏览器温州 建网站的公司 新
  • 怎么做网站推广佳木斯软件技术专科生的出路
  • 网站内容更新用什么wordpress android开源