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

湛江模板建站多少钱济南pc网站建设公司

湛江模板建站多少钱,济南pc网站建设公司,app排名,创意设计Given two singly linked lists L1​a1​→a2​→⋯→an−1​→an​ and L2​b1​→b2​→⋯→bm−1​→bm​. If n≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like a1​→a2​→bm​→a3​→a4​→bm−1​⋯. For ex…

Given two singly linked lists L1​=a1​→a2​→⋯→an−1​→an​ and L2​=b1​→b2​→⋯→bm−1​→bm​. If n≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list like a1​→a2​→bm​→a3​→a4​→bm−1​⋯. For example, given one list being 6→7 and the other one 1→2→3→4→5, you must output 1→2→7→3→4→6→5.

Input Specification:

Each input file contains one test case. For each case, the first line contains the two addresses of the first nodes of L1​ and L2​, plus a positive N (≤105) which is the total number of nodes given. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

Then N lines follow, each describes a node in the format:

Address Data Next

where Address is the position of the node, Data is a positive integer no more than 105, and Next is the position of the next node. It is guaranteed that no list is empty, and the longer list is at least twice as long as the shorter one.

Output Specification:

For each case, output in order the resulting linked list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:

00100 01000 7
02233 2 34891
00100 6 00001
34891 3 10086
01000 1 02233
00033 5 -1
10086 4 00033
00001 7 -1

Sample Output:

01000 1 02233
02233 2 00001
00001 7 34891
34891 3 10086
10086 4 00100
00100 6 00033
00033 5 -1

题目大意:给定两个单链表L1 = a1 → a2 → … → an-1 → an,和L2 = b1 → b2 → … → bm-1 → bm,将较短的那个链表逆序,然后将之并入比较长的那个链表,得到一个形如a1 → a2 → bm → a3 → a4 → bm-1 … 的结果,例如给定两个链表分别为6→7和1→2→3→4→5,你应该输出1→2→7→3→4→6→5。

分析:由于题目没有说哪个链表更长,因此首先要先确定短的链表是哪个,再把短的链表逆序。之后长的链表每前进2步,短的链表前进1步。注意有可能n=2*m的边界条件。

#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
#define db5(x,y,z,r,w) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<", "<<#w<<"="<<(w)<<endl
using namespace std;typedef struct node
{int val,next,id;
}node;int main(void)
{#ifdef testfreopen("in.txt","r",stdin);//freopen("in.txt","w",stdout);clock_t start=clock();#endif //testint r1,r2,n;scanf("%d%d%d",&r1,&r2,&n);node num[100000];for(int i=0;i<100000;++i)num[i].val=0,num[i].next=-1,num[i].id=i;for(int i=0;i<n;++i){int a,b,c;scanf("%d%d%d",&a,&b,&c);num[a].val=b,num[a].next=c;}int t1=0,t2=0,pos1=r1,pos2=r2;while(pos1!=-1)t1++,pos1=num[pos1].next;while(pos2!=-1)t2++,pos2=num[pos2].next;if(t1<t2)swap(r1,r2);pos1=r1,pos2=r2;int temp=-1,next=-1;while(pos2!=-1){if(num[pos2].next==-1)r2=pos2;next=num[pos2].next,num[pos2].next=temp,temp=pos2,pos2=next;}//    pos2=r2;
//    while(pos2!=-1)
//    {
//        printf("%05d %d %05d\n",num[pos2].id,num[pos2].val,num[pos2].next);
//        pos2=num[pos2].next;
//    }printf("\n");pos2=r2;int t=0;while(pos1!=-1){if(t<2||pos2==-1){if(pos1==r1)printf("%05d %d",num[pos1].id,num[pos1].val);else printf(" %05d\n%05d %d",num[pos1].id,num[pos1].id,num[pos1].val);t++;pos1=num[pos1].next;}else{printf(" %05d\n%05d %d",num[pos2].id,num[pos2].id,num[pos2].val);pos2=num[pos2].next;t=0;}}if(pos2!=-1)printf(" %05d\n%05d %d",num[pos2].id,num[pos2].id,num[pos2].val);pos2=num[pos2].next;t=0;printf(" -1\n");#ifdef testclockid_t end=clock();double endtime=(double)(end-start)/CLOCKS_PER_SEC;printf("\n\n\n\n\n");cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位#endif //testreturn 0;
}

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

相关文章:

  • 新乡电商网站建设平面设计有哪些网站
  • 广州网站建设 讯度网络wordpress 导航栏效果
  • 网站备案帐号是什么意思wordpress 视频站模板下载失败
  • 西安市网站制作公司H5 网站
  • 做网站群网络营销师培训学校
  • 西安外贸网站建设公司免费收录网站大全
  • 博客网站wordpress要怎么网络做推广
  • 网站上传都传些什么文件企业号官网入口
  • 广州白云机场网站建设电商网站建设渠道
  • 青海省城乡建设网站wordpress文章出问题
  • 京东网站 用什么做的tp5手机网站开发
  • 简单网站如何制作定制网站开发的目的是什么
  • 外贸流程一般包括哪几个部分滕州seo
  • 上海网站设计公司电话wordpress单页瀑布流
  • 自己做的网站如何上传网上企业官网用什么系统
  • 网站开发就业前景怎么样wordpress里的导航用什么
  • 网站开发工程师招聘要求深圳网络服务有限公司
  • 网站开发公司 经营范围建筑网站源码
  • 外贸网站建设需要注意什么wordpress手机端怎么用
  • django网站开发规范网页设计与制作教程西北工业大学出版社
  • 哪个企业的网站做的比较好网站建设小白到精通需要
  • 丹徒网站建设哪家好山东省建设局拖欠工资网站
  • 网站安全 重要性邯郸建设网站的公司哪家好
  • 芜湖手机网站开发网站个人备案需要什么资料
  • 台州卫浴网站建设全网营销软件
  • iis网站模板网页设计的设计思路怎么写
  • 网站怎么做uc整合重庆江北网站建设公司
  • 怎样在网站上做办公家具wordpress 用户点赞插件
  • 定制高端网站建设报价品牌策划岗位职责
  • iis6.0做网站压缩有后台的网站模版