• 离散化模板


     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 using namespace std;
     5 const int maxn=100000;
     6 int a[maxn];
     7 int b[maxn];
     8 int n;
     9 int main()
    10 {
    11     int m=0;
    12     cin>>n;//元素个数
    13     for(int i=1;i<=n;++i)
    14     {
    15     scanf("%d",&a[i]);
    16     b[++m]=a[i];//b[]作为离散化的数组
    17     }
    18     sort(b+1,b+1+m);//将b数组排序,因为是从b[1]开始存储的,所以要b+1
    19     m=unique(b+1,b+1+m)-b-1;//去重操作,返回不同元素的个数
    20     for(int i=1;i<=n;++i)
    21     cout<<lower_bound(b+1,b+1+m,a[i])-b<<" ";
    22    // while(1);
    23     return 0;
    24 }
    View Code

    转自http://blog.csdn.net/Cirspring/article/details/51836776

  • 相关阅读:
    二进制编译http
    http服务
    FTP服务
    DAY01
    直流电机调速作业
    机械大楼电梯控制项目
    仿真作业
    第六周作业
    第五周作业
    第四周仿真作业
  • 原文地址:https://www.cnblogs.com/SXia/p/7143255.html
Copyright © 2020-2023  润新知