出现次数 哈希表
問題描述
依次讀入 N(0 < N < 1,000,000)個(gè)整數(shù)( <=2×109
),計(jì)算每個(gè)數(shù)是第幾次出現(xiàn)。
樣例輸入
10 10 30 20 1 1 30 30 20 2 1樣例輸出
1 1 1 1 2 2 3 2 1 3限制和約定
時(shí)間限制:1s
空間限制:128MB
#include<cstdio> #include<cmath> using namespace std; int p=1000007,a[1000001]={0},first[1000008]={0},next[1000001],noat[1000001]; int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++){bool found=false;scanf("%d",&a[i]);int s=a[i]%p;for(int j=first[s];j>0;j=next[j]){if(a[i]==a[j]){found=true;noat[i]=noat[j]+1;noat[j]++;break;}}if(found==false) {next[i]=first[s];first[s]=i;}printf("%d ",noat[i]+1);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/hfang/p/11240025.html
總結(jié)
- 上一篇: 集合 哈希表
- 下一篇: 单词背诵【CodeVS3013】 哈希