跳到正文

题解

P4305 [JLOI2011] 不重复数字 题解

Gold_Coin约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月11日
篇幅
约 1 分钟
题目
P4305

版本

  1. v1当前

题中说给出的数在32位有符号整数范围内。如果要开这么大的桶是开不了的。 所以这里用到了一个新的容器- unordered_map,该容器在c++11下才可以使用,所以需要修改dev-c++得编译属性,加上如图所示配置。

dev-c++编译配置

C++
#include <bits/stdc++.h>
#include <unordered_map>//map头文件
using namespace std;

int main() {
    int t, n, x;
    cin >> t;
    unordered_map<long long, int> mp;//定义map容器
    while (t--) {
    	cin >> n;
    	mp.clear();//清空mp
    	int arr[n];
    	for (int i = 0; i < n; i++) {
    		cin >> x;
    		arr[i] = x;
    		mp[x] = 1;//将数放进对应的桶
		}
		for (int i = 0; i < n; i++) {
			if (mp[arr[i]] == 1) {
				mp[arr[i]]--;
				cout << arr[i] << " ";
			}
		}
		cout << endl;
	}
    return 0;
}
原文