zoukankan      html  css  js  c++  java
  • 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
    ",b[tot].v);
    22     }
    23     return 0;
    24 }

    20160610

  • 相关阅读:
    twemproxy配置
    tomcat远程调试
    hadoop配置
    kafka原理分析
    hive-sql
    P1983 车站分级
    拓扑排序
    洛谷P1982 小朋友的数字
    字典树Trie
    城市交通费
  • 原文地址:https://www.cnblogs.com/YuanZiming/p/5778221.html
Copyright © 2011-2022 走看看