码迷,mamicode.com
首页 > 其他好文 > 详细

离散化模板

时间:2017-07-09 23:14:46      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:gif   out   sort   using   while   for   amp   tail   std   

技术分享
 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

离散化模板

标签:gif   out   sort   using   while   for   amp   tail   std   

原文地址:http://www.cnblogs.com/SXia/p/7143255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!