BZOJ 2761 不重复数字 set
题目链接:
https://www.lydsy.com/JudgeOnline/problem.php?id=2761
题目大意:
给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。
思路:
set
1 #include<bits/stdc++.h> 2 #define IOS ios::sync_with_stdio(false);//不可再使用scanf printf 3 #define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时 4 #define Min(a, b) ((a) < (b) ? (a) : (b)) 5 #define Mem(a) memset(a, 0, sizeof(a)) 6 #define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1)) 7 #define MID(l, r) ((l) + ((r) - (l)) / 2) 8 #define lson ((o)<<1) 9 #define rson ((o)<<1|1) 10 #define Accepted 0 11 #pragma comment(linker, "/STACK:102400000,102400000")//栈外挂 12 using namespace std; 13 inline int read() 14 { 15 int x=0,f=1;char ch=getchar(); 16 while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} 17 while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 18 return x*f; 19 } 20 typedef long long ll; 21 const int MOD = 1000000007;//const引用更快,宏定义也更快 22 const double eps = 1e-10; 23 const double pi = acos(-1); 24 const int INF = 0x3f3f3f3f; 25 const int maxn = 10000 + 10; 26 27 set<int>s; 28 int main() 29 { 30 int T; 31 scanf("%d", &T); 32 while(T--) 33 { 34 int n, x, first = 1; 35 scanf("%d", &n); 36 s.clear(); 37 while(n--) 38 { 39 scanf("%d", &x); 40 if(s.count(x))continue; 41 s.insert(x); 42 if(first)first = 0; 43 else printf(" "); 44 printf("%d", x); 45 } 46 puts(""); 47 } 48 }
越努力,越幸运