万紫千红,求调

P4305 [JLOI2011] 不重复数字

这样是60pts,还有4个re是因为有负数下标 ```cpp #include<bits/stdc++.h> using namespace std; const int N=1e8+50; long long t,n,a; bool b[N]; int main(){ cin>>t; for(int v=1;v<=t;v++){ cin>>n; for(int i=1;i<=n;i++){ cin>>a; if(b[a]!=1){ b[a]=1; cout<<a<<' '; } } cout<<endl; memset(b,0,sizeof b); } return 0; } ```
by spencer @ 2024-06-16 09:38:49


@[zyh071](/user/995589) 而且用桶的话即使没有负数大概率还是会被卡的,建议写哈希或者排序
by spencer @ 2024-06-16 09:41:46


@[zyh071](/user/995589) 用STL例的`unordered_map` ```cpp #include<bits/stdc++.h> using namespace std; #define int long long int t,n,x; unordered_map<int,bool>s; signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> t; for(int i = 1;i <= t; i++){ s.clear(); cin >> n; for(int j = 1; j <= n; j++){ cin >> x; if(s[x] == false){ cout << x << " "; s[x] = true; } } cout << "\n"; } return 0; } ```
by King_and_Grey @ 2024-06-16 09:43:45


写错了,是`里`的
by King_and_Grey @ 2024-06-16 09:44:17


~~大佬的东西我看不懂~~。 ###### 送上个蒟蒻的办法,千万莫嫌笨 ```cpp #include<bits/stdc++.h> using namespace std; struct num{ long long z; int id; bool tool; }sum[int(5e4)+100]; //五乘十的四次方 (最大上限)还多开100个 bool cntz(num a,num b){ if(a.z!=b.z)return a.z>b.z; else return a.id<b.id; } bool cntid(num a,num b){ return a.id<b.id; } int main(){ ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ int ans; cin>>ans; for(int i=1;i<=ans;i++){ cin>>sum[i].z; sum[i].id=i; sum[i].tool=false; } sort(sum+1,sum+ans+1,cntz); for(int i=2;i<=ans;i++){ if(int(sum[i].z)==int(sum[i-1].z))sum[i].tool=true; } sort(sum+1,sum+ans+1,cntid); for(int i=1;i<=ans;i++)if(!sum[i].tool)cout<<sum[i].z<<' '; cout<<endl; } } ```
by FearlessWarriors @ 2024-07-08 14:23:11


感谢各位DL们
by zyh071 @ 2024-07-25 14:03:19


|