1097. Deduplication on a Linked List (25)
来源:互联网 发布:美国博士知乎 编辑:程序博客网 时间:2024/05/21 17:45
日常水题
AC代码:
#include <bits/stdc++.h>using namespace std;struct node{ int now; int value; int next;};int main(void){ int start, n; int i; cin >> start >> n; vector<node> arr(100000); for (i = 0; i < n; i++) { node temp; cin >> temp.now >> temp.value >> temp.next; arr[temp.now] = temp; } set<int> test; vector<node> res; test.insert(abs(arr[start].value)); int temp = start; while (1) { int ne = arr[temp].next; if (ne == -1) break; if (test.count(abs(arr[ne].value)) == 0) { test.insert(abs(arr[ne].value)); temp = ne; } else { res.push_back(arr[ne]); arr[temp].next = arr[ne].next; } } while (1) { if (arr[start].next == -1) break; printf("%05d %d %05d\n", arr[start].now, arr[start].value, arr[start].next); start = arr[start].next; } printf("%05d %d -1\n", arr[start].now, arr[start].value); if (res.size() == 0) return 0; for (i = 0; i < res.size() - 1; i++) { res[i].next = res[i+1].now; } res[i].next = -1; for (i = 0; i < res.size(); i++) { printf("%05d %d ", res[i].now, res[i].value); if (res[i].next != -1) printf("%05d\n", res[i].next); else printf("-1\n"); }}
阅读全文
0 0
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 1097. Deduplication on a Linked List (25)
- 72. Edit Distance
- lucene源码-倒排索引的读过程
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合
- 怎么在虚拟机上部署你自己的项目?
- 翻转子串
- 1097. Deduplication on a Linked List (25)
- 第十六日总结
- 呆萌了
- Scrapy--爬取全国地区对应的天气网址
- poj3468:A Simple Problem with Integers(线段树lazy)
- POJ 1039 Pipe <计算几何>
- test_title
- 刷题#R1
- javascript编解码