bzoj2761[JLOI2011]不重复数字

bzoj2761[JLOI2011]不重复数字

题意:

给出N个数,要求把其中重复的去掉,只保留第一次出现的数。n≤50000

题解:

一道令管理员都后悔加入的水题,按大小排序后unique,再按读入顺序排序即可。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define inc(i,j,k) for(int i=j;i<=k;i++)
 5 using namespace std;
 6 
 7 inline int read(){
 8     char ch=getchar(); int f=1,x=0;
 9     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
10     return f*x;
11 }
12 int t,n,tot;
13 struct nd{int v,id;};
14 bool cmp1(nd a,nd b){if(a.v!=b.v)return a.v<b.v;else return a.id<b.id;}
15 bool cmp2(nd a,nd b){return a.id<b.id;};
16 nd a[50010],b[50010];
17 int main(){
18     t=read(); while(t--){
19         n=read(); inc(i,1,n)a[i].v=read(),a[i].id=i; sort(a+1,a+n+1,cmp1); tot=0;
20         inc(i,1,n)if(i==1||a[i].v!=a[i-1].v)b[++tot]=a[i]; sort(b+1,b+tot+1,cmp2);
21         inc(i,1,tot-1)printf("%d ",b[i].v); printf("%d\n",b[tot].v);
22     }
23     return 0;
24 }

 

20160610

转载于:https://www.cnblogs.com/YuanZiming/p/5778221.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值