寒假总结 22-1-9

1-8,1-9两天的总结

腾讯会议时长:6h52min+4h39min+电脑端崩溃少了的2h

链表补题x2,直接上代码了:

A:

1312: 链表(软工)
时间限制:1s
 
内存限制:128MB

题目描述

有两个链表a和b,从a、b中删除它两重复的元素(只要重复就删除),并对删除后的a链表进行升序排序,b链表进行降序排序。a 的长度为m,b 的长度为n

输入格式

输入a,b的长度m,n

a、b链表

输出格式

处理后的a、b链表

样例输入content_copy

9
6
1 2 3 4 5 6 7 8 6
5 6 7 10 0 5

样例输出content_copy

1 2 3 4 8 
10 0 

提示/说明

 本题是多组输入。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<malloc.h>
typedef struct zz{
	int data;
	struct zz *next;
}zz;

zz * add(zz *head,int num);
zz * sq(zz *head1,zz *head2);
zz * sort1(zz *head1,int m);
zz * sort2(zz *head2,int n);
zz * deletehead(zz *head);
void deletehead1or2(zz *head1,zz *head2);
void puthead(zz *head);

int m,n;

int main(){
	while(~scanf("%d",&m)){
		scanf("%d",&n);
		zz *head1=(zz*)malloc(sizeof(zz)),*head2=(zz*)malloc(sizeof(zz));
		head1->data=-1;head2->data=-1;head1->next=NULL;head2->next=NULL;
		head1=add(head1,m);
		head2=add(head2,n);
		head1=sort1(head1,m);
		head2=sort2(head2,n);
		head1=deletehead(head1);
		head2=deletehead(head2);
		deletehead1or2(head1,head2);
		puthead(head1);
		puthead(head2);
	}
	system("pause");
	return 0;
}

zz * add(zz *head,int num){
	zz *pr=head;
	for(int i=0;i<num;i++){
		zz *p=(zz*)malloc(sizeof(zz));
		p->next=NULL;
		scanf("%d",&(p->data));
		pr->next=p;pr=pr->next;
	}
	return head;
}

zz * sort1(zz *head1,int m){
	zz *p=head1->next;
	for(int i=0;i<m;i++){
		zz *pr=p;
		for(int j=i;j<m;j++){
			if(pr->data<p->data){
				int num=pr->data;pr->data=p->data;p->data=num;
			}
			pr=pr->next;
		}
		p=p->next;
	}
	return head1;
}

zz * sort2(zz *head2,int n){
	zz *p=head2->next;
	for(int i=0;i<n;i++){
		zz *pr=p;
		for(int j=i;j<n;j++){
			if(pr->data>p->data){
				int num=pr->data;pr->data=p->data;p->data=num;
			}
			pr=pr->next;
		}
		p=p->next;
	}
	return head2;
}


void puthead(zz *head){
	zz *p=head->next,*pr=head;
	while(p!=NULL){
		free(pr);pr=p;
		printf("%d ",p->data);p=p->next;
		
	}
	printf("\n");
}

zz * deletehead(zz *head){
	zz *p=head->next,*pl=head,*pr=head->next->next;
	while(pr!=NULL){
		if(p->data==pr->data){
			pl->next=pr;
			zz *i=p;p=pr;pr=pr->next;free(i);
		}else{
			pl=p;p=pr;pr=pr->next;
		}
	}
	return head;
}

void deletehead1or2(zz *head1,zz *head2){
	zz *p1=head1,*pr1=head1->next;
	while(pr1!=NULL){
		int tip=0;
		zz *p2=head2,*pr2=head2->next;
		while(pr2!=NULL){
	//		printf("%d %d\n",pr1->data,pr2->data);
			if(pr1->data==pr2->data){
		//		printf("!\n");
				p1->next=pr1->next;p2->next=pr2->next;
				pr1=pr1->next;pr2=pr2->next;
				tip=1;
			}else{
				p2=pr2;pr2=pr2->next;
			}
		}
		if(tip==0){
			p1=pr1;pr1=pr1->next;
		}
	}
}

tips:看了别人题解的提示,把单个链表中重复的元素先删除,再比较两个链表间重复元素并删除

F:

1381: 双向链表
时间限制:1s
 
内存限制:128MB

题目描述

构建一个双向链表并进行删除和插入操作,按要求输出。

输入格式

 

输入:

第一行输入元素个数M

第二行输入M个元素

第三行输入删除位置,位置为0时不删除

第四行输入插入位置和插入元素

第五行输入输出时的起始位置

输出格式

按要求的起始位置输出链表

样例输入content_copy

8
1 2 3 4 5 6 7 8
6
6 6
5

样例输出content_copy

5 6 7 8 1 2 3 4 
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<malloc.h>
typedef struct zz{
	int num;
	struct zz *op,*ed;
}zz;

zz *add(zz *head);
zz *sq(zz *head,int t);
zz *jia(zz *head,int t,int nn);
void putid(zz *head,int ok);
int m;
int main(){
	zz * head=NULL;
	scanf("%d",&m);
	for(int i=1;i<=m;i++)head=add(head);
	int t;scanf("%d",&t);
	if(t!=0)head=sq(head,t);
	else m+=1;
    int nn;	scanf("%d%d",&t,&nn);head=jia(head,t,nn);
	int ok;scanf("%d",&ok);putid(head,ok);
	system("pause");
	return 0;
}


zz *add(zz *head){
	zz *p=(zz*)malloc(sizeof(zz));
	int num;scanf("%d",&num);p->num=num;
	if(head==NULL){
		head=p;p->ed=head;p->op=head;
	}
	else{
		zz *pr=head;
		while(pr->ed!=head)pr=pr->ed;
		pr->ed=p;p->op=pr;p->ed=head;head->op=p;
	}
	return head;
}

zz *sq(zz *head,int t){
	zz *p=head;
	if(t<=m-t){
		for(int i=1;i<t;i++)p=p->ed;
		p->op->ed=p->ed;p->ed->op=p->op;
		free(p);
	}
	else{
		for(int i=0;i<=m-t;i++)p=p->op;
		p->op->ed=p->ed;p->ed->op=p->op;
		free(p);
	}
	return head;
}

zz *jia(zz *head,int t,int nn){
	zz *pr=head,*p=(zz*)malloc(sizeof(zz));;
	p->num=nn;
	for(int i=1;i<t-1;i++)pr=pr->ed;
	pr->ed->op=p;p->ed=pr->ed;p->op=pr;pr->ed=p;
	return head;
}


void putid(zz *head,int ok){
	zz *p=head;
	if(ok<=m-ok){
		for(int i=1;i<ok;i++)p=p->ed;
		for(int i=1;i<=m;i++){
			printf("%d ",p->num);p=p->ed;
		}
	}
	else{
		for(int i=0;i<=m-ok;i++)p=p->op;
		for(int i=1;i<=m;i++){
			printf("%d ",p->num);p=p->ed;
		}
	}
}

tips:开始的时候打算记录每个元素的序号,结果删除和增加元素需要改变序号,提交的时候超时了,转换思路不用序号就过了

洛谷搜索题组的题目x3

1.

单词方阵 - 洛谷https://www.luogu.com.cn/problem/P1101写的时候老是格式错误,套了两个数据点出来自己测试没问题,交了就WA,搞了一白天,晚上想到用两个getchar试试,结果过了,就离谱

虽然题目意思是八个方向去搜索,但是可以只用四个方向,两个字符串,一个正序一个逆序,

 

2.

填涂颜色 - 洛谷https://www.luogu.com.cn/problem/P1162题目条件比较单一,规定了边界只能上下左右,直接找出一个角(左上),然后涂色就完了

3.

迷宫 - 洛谷https://www.luogu.com.cn/problem/P1605 不难,但是试了几次

 4.(没过)

马的遍历 - 洛谷https://www.luogu.com.cn/problem/P1443

 写了两遍,都是深搜,倒数第二个数据点估计是400x400,明天学一下怎么广搜处理

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值