zoukankan      html  css  js  c++  java
  • 团体程序设计天梯赛 L2-002 链表去重 (25分)

    题目链接:

    L2-002 链表去重

    思路:

    将两个链表分开存储、输出即可;

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int maxn = 1e6 + 5;
    bool vst[maxn];
    int nex[maxn], val[maxn];
    void print(vector<int> & v){
    	if(!v.size()) return;
    	printf("%05d %d ", v[0], val[v[0]]);
    	for(int i = 1; i < v.size(); i++){
    		printf("%05d
    %05d %d ",v[i], v[i], val[v[i]]);	
    	}
    	printf("-1
    ");	
    }
    
    int main() {
    #ifdef MyTest
    	freopen("Sakura.txt", "r", stdin);
    #endif	
    	int s, n;
    	scanf("%d %d", &s, &n);
    	for(int i = 0; i < n; i++) {
    		int p;
    		scanf("%d", &p);
    		scanf("%d %d", val + p, nex + p);
    	}
    	vector<int> x, y;
    	while(~s) {
    		if(!vst[abs(val[s])]){
    			vst[abs(val[s])] = true;
    			x.push_back(s); 	
    		}else y.push_back(s);
    		s = nex[s];
    	}
    	print(x);
    	print(y);
    	return 0;
    }
    
  • 相关阅读:
    re模块
    collections模块
    hashlib模块
    序列号模块
    random模块
    sys模块
    OS模块
    工厂模式
    Go语言之直接选择排序
    Go语言之直接插入排序
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308687.html
Copyright © 2011-2022 走看看