模拟题,用链表来进行模拟

 # include <stdio.h>
# include <stdlib.h>
typedef struct node
{
int num;
struct node *q;
struct node *h;
}node;
struct Node
{
node *start;
node *end;
int sum;
}m[];
int main()
{
int k;
scanf("%d", &k);
while (k--)
{
int n, p;
scanf("%d%d", &n, &p);
for (int i = ; i <= n; i++)
{
m[i].end = NULL;
m[i].start = NULL;
m[i].sum = ;
}
for (int i = ; i<p; i++)
{
int op, s, v, t;
scanf("%d", &op);
if (op == )
{
scanf("%d%d", &s, &v);
if (m[s].sum == )
{
m[s].start = (node *)malloc(sizeof(node));
m[s].start->num = v;
m[s].start->q = NULL;
m[s].start->h = NULL;
m[s].end = NULL;
m[s].sum = ;
}
else
if (m[s].sum == )
{
m[s].end = (node *)malloc(sizeof(node));
m[s].end->num = v;
m[s].end->q = m[s].start;
m[s].end->h = NULL;
m[s].start->h = m[s].end;
m[s].sum = ;
}
else
{
node * z = (node *)malloc(sizeof(node));
z->num = v;
z->q = m[s].end;
z->h = NULL;
m[s].end->h = z;
m[s].end = z;
m[s].sum++;
}
}
else
if (op == )
{
scanf("%d", &s);
if (m[s].sum == )
printf("EMPTY\n");
else
{
m[s].sum--;
if (m[s].sum != )
printf("%d\n", m[s].end->num);
else
printf("%d\n", m[s].start->num);
if (m[s].sum != )
{
node *z = m[s].end->q;
z->h = NULL;
m[s].end = z;
}
else
{
m[s].end = NULL;
m[s].start = NULL;
}
}
}
else
{
scanf("%d%d", &s, &t);
if (m[s].sum == )
{
m[s].end = m[t].end;
m[s].start = m[t].start;
m[s].sum = m[t].sum;
m[t].sum = ;
m[t].end = NULL;
m[t].start = NULL;
}
else
if (m[s].sum == )
{
m[s].sum += m[t].sum;
m[t].sum = ;
if (m[t].start != NULL)
{
m[s].end = m[t].start;
m[s].start->h = m[t].start;
m[s].end->q = m[s].start;
if (m[t].end != NULL)
m[s].end = m[t].end;
else
m[s].end = m[t].start;
}
m[t].start = NULL;
m[t].end = NULL;
}
else
{
m[s].sum += m[t].sum;
m[t].sum = ;
if (m[t].start != NULL)
{
m[s].end->h = m[t].start;
m[t].start->q = m[s].end;
if (m[t].end != NULL)
m[s].end = m[t].end;
else
m[s].end = m[t].start;
}
m[t].start = NULL;
m[t].end = NULL;
}
}
}
}
//system("pause");
return ;
}

最新文章

  1. OpenGL超级宝典笔记----渲染管线
  2. 《深入理解Java虚拟机》内存分配策略
  3. bzoj2729 [HNOI2012]排队
  4. boot/setup.S
  5. WPF嵌入百度地图完整实现
  6. intellij idea社区版 &amp; maven &amp; git &amp; tomcat/jetty 的struts2项目的搭建
  7. C# is 与 as 运算符
  8. lua math libary
  9. ThinkPHP - 组织分类结构
  10. hdu 4771 Stealing Harry Potter&amp;#39;s Precious
  11. ajax跨域实现api 接口调用
  12. php 抽象类abstract
  13. 1分钟解决VS每次运行都显示“正在还原nuget程序包”问题
  14. oracle 表所占空间统计
  15. 针对小程序for循环绑定数据,实现toggle切换效果(交流QQ群:604788754)
  16. python批量下载微信好友头像,微信头像批量下载
  17. idea导入maven项目 傻瓜都能看懂
  18. Redis自学笔记:4.1进阶-事务
  19. C# string 是不可变的,指什么不可变
  20. 大表分批删除脚本之MySQL版

热门文章

  1. hibernate属性配置
  2. 对于iPhone描述文件的签名认证
  3. SAM初步
  4. bzoj4486: [Jsoi2015]串分割
  5. weixin报警脚本
  6. DGA域名——可以每天只生成一个域名,因此最多存在365个 DGA域名;
  7. YCSB-mapkeeper
  8. albus就是要第一个出场(线性基)
  9. Python之Numpy详细教程
  10. @Autowired注解和启动自动扫描的三种方式(spring bean配置自动扫描功能的三种方式)