1 solutions
-
0
数据太大了,开个数组装不了最大1e18个元素,所以这个时候有自动扩容机制的map就显得很有用
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<map> using namespace std; const int N = 100005; int n, m, ans, a[N]; map<int, int> elm; int main() { while (cin >> n >> m)//要求输入多组数据 { for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) if (!elm[a[i]]) { elm[a[i] * m] = 1; ans++; } //中心思想:在map中删区互斥的数 cout << ans<<endl; ans = 0; memset(a, 0, sizeof(a)); elm.clear();//初始化变量,数组和map } return 0; }
- 1
Information
- ID
- 1097
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- 6
- Tags
- # Submissions
- 55
- Accepted
- 18
- Uploaded By