日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

PTA L2-002 链表去重

發布時間:2025/4/16 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PTA L2-002 链表去重 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:https://pintia.cn/problem-sets/994805046380707840/problems/994805072641245184

第一次做鏈表題,有時間多看看

解釋的話直接看這篇題解:https://www.liuchuo.net/archives/2125

1 #include <bits/stdc++.h> 2 using namespace std; 3 const int inf=1<<30; 4 typedef long long ll; 5 typedef pair<int,int> P; 6 const double pi=acos(-1); 7 const int mod=1e8+7; 8 const int maxn=1e5+7; 9 const int maxm=6300; 10 struct node{ 11 int adress,val,next,num; 12 }a[maxn]; 13 bool exist[maxn]; 14 int cnt,cnt1,cnt2; 15 bool cmp(const node &a,const node &b){ 16 return a.num<b.num; 17 } 18 int main(){ 19 int begin,n;scanf("%d%d",&begin,&n); 20 for(int i=0;i<maxn;i++){ 21 a[i].num=2*maxn; 22 } 23 for(int i=0;i<n;i++){ 24 int x,y,z;scanf("%d",&x); 25 a[x].adress=x; 26 scanf("%d%d",&a[x].val,&a[x].next); 27 } 28 for(int i=begin;i!=-1;i=a[i].next){ 29 if(!exist[abs(a[i].val)]){ 30 exist[abs(a[i].val)]=1; 31 a[i].num=cnt1; 32 cnt1++; 33 } 34 else{ 35 a[i].num=cnt2+maxn; 36 cnt2++; 37 } 38 } 39 cnt=cnt1+cnt2; 40 sort(a,a+maxn,cmp); 41 for(int i=0;i<cnt;i++){ 42 if(i==cnt1-1||i==cnt-1) printf("%05d %d -1\n",a[i].adress,a[i].val); 43 else printf("%05d %d %05d\n",a[i].adress,a[i].val,a[i+1].adress); 44 } 45 return 0; 46 }

?

轉載于:https://www.cnblogs.com/qingjiuling/p/10475917.html

總結

以上是生活随笔為你收集整理的PTA L2-002 链表去重的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。