PAT 团体天梯赛 L2-002. 链表去重
来源:互联网 发布:如何用邮箱注册知乎 编辑:程序博客网 时间:2024/05/19 22:02
题意:中文不说了
方法:直接数组模拟链表就好了 有一个坑点 链表不一定全部包含给出的那些数据 可能只用到部分数据
#include <iostream>#include <cstdio>#include <cstring>#include <queue>#include <algorithm>#include <string>#include <map>#include <math.h>#include <queue>#include <climits>#include <stack>using namespace std;int Next[100005];int ans[100005][3];int ans2[100005][3];int vis[100005];int ss[100005];int main(){ int fir, n; scanf("%d%d", &fir, &n); memset(Next, -1, sizeof(Next)); for(int i = 0; i < n; i++){ int a, b, c; scanf("%d%d%d", &a, &b, &c); ss[a] = b; Next[a] = c; } int cnt1 = 0, cnt2 = 0; memset(vis, 0, sizeof(vis)); for(; fir != -1; fir = Next[fir]){ int key = ss[fir]; if(vis[abs(key)]){ ans2[cnt2][0] = fir; ans2[cnt2][1] = key; cnt2++; } else { ans[cnt1][0] = fir; ans[cnt1][1] = key; vis[abs(key)] = 1; cnt1++; } } for(int i = 0; i < cnt1 - 1; i++) ans[i][2] = ans[i + 1][0]; for(int i = 0; i < cnt2 - 1; i++) ans2[i][2] = ans2[i + 1][0]; ans[cnt1 - 1][2] = -1; ans2[cnt2 - 1][2] = -1; for(int i = 0; i < cnt1 - 1; i++){ printf("%05d %d %05d\n", ans[i][0], ans[i][1], ans[i][2]); } if(cnt1 ) printf("%05d %d -1\n", ans[cnt1 - 1][0], ans[cnt1 - 1][1]); for(int i = 0; i < cnt2 - 1; i++){ printf("%05d %d %05d\n", ans2[i][0], ans2[i][1], ans2[i][2]); } if(cnt2) printf("%05d %d -1\n", ans2[cnt2 - 1][0], ans2[cnt2 - 1][1]); return 0;}
0 0
- PAT 团体天梯赛 L2-002. 链表去重
- L2-002. 链表去重-PAT团体程序设计天梯赛GPLT
- 团体程序设计天梯赛-练习集 L2-002. 链表去重
- 团体程序设计天梯赛-练习集L2-002. 链表去重
- 团体程序设计天梯赛L2-002 链表去重
- 团体程序设计天梯赛L2-002链表去重
- PAT 团体天梯赛 L2-001 紧急救援 (迪杰斯特拉)
- L2-014. 列车调度-PAT团体程序设计天梯赛GPLT
- L2-003. 月饼-PAT团体程序设计天梯赛GPLT
- L2-009. 抢红包-PAT团体程序设计天梯赛GPLT
- L2-007. 家庭房产-PAT团体程序设计天梯赛GPLT
- L2-003. 月饼-PAT团体程序设计天梯赛GPLT
- 团体程序设计天梯赛L2-002 链表去重(模拟)
- 团体程序设计天梯赛-练习集 L2-002. 链表去重 解题报告
- 团体程序设计天梯赛 决赛 L2 红色警报
- 团体程序设计天梯赛L2-003 月饼
- 团体程序设计天梯赛L2-013 红色警报
- 团体程序设计天梯赛L2-003月饼
- CF686B A - Little Robber Girl's Zoo
- 接口测试笔记1
- 动态规划之钢筋切割问题
- 一起talk C栗子吧(第一百七十三回:C语言实例--关闭终端中的缓冲功能一)
- 使用dom4j解析xml文件
- PAT 团体天梯赛 L2-002. 链表去重
- 这只是起点_16_07_07
- tyvj 1391 走廊泼水节
- java之枚举类型
- UIScrollView contentInset 属性详解
- samba映射拷贝比linux sz命令快多了
- Guava collections -- Lists
- 善用php-fpm的慢执行日志slow log,分析php性能问题
- Ping,traceroute和mtr