zoukankan      html  css  js  c++  java
  • [BZOJ2761][JLOI2011]不重复数字 暴力

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2761

    直接暴力。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int inline readint(){
     6     int Num=0,Flag=1;char ch;
     7     while((ch=getchar())<'0'||ch>'9') if(ch=='-') break;
     8     if(ch=='-') Flag=-1; else Num=ch-'0';
     9     while((ch=getchar())>='0'&&ch<='9') Num=Num*10+ch-'0';
    10     return Num*Flag;
    11 }
    12 struct DATA{
    13     int num,idx;
    14     bool tag;
    15 }a[50010];
    16 bool cmp1(const DATA &a,const DATA &b){
    17     return a.num!=b.num?a.num<b.num:a.idx<b.idx;
    18 }
    19 bool cmp2(const DATA &a,const DATA &b){
    20     return a.idx<b.idx;
    21 }
    22 int tmp[50010],cnt;
    23 int main(){
    24     int Test=readint();
    25     while(Test--){
    26         int N=readint();
    27         for(int i=1;i<=N;i++){
    28             a[i].num=readint();
    29             a[i].idx=i;
    30         }
    31         sort(a+1,a+1+N,cmp1);
    32         a[1].tag=true;
    33         for(int i=2;i<=N;i++) a[i].tag=a[i-1].num!=a[i].num;
    34         sort(a+1,a+1+N,cmp2);
    35         cnt=0;
    36         for(int i=1;i<=N;i++)
    37             if(a[i].tag)
    38                 tmp[++cnt]=a[i].num;
    39         for(int i=1;i<cnt;i++) printf("%d ",tmp[i]);
    40         printf("%d",tmp[cnt]);
    41         if(Test>=1) putchar('
    ');
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    STL整理之map
    链表及数组模拟链表
    树链剖分详解
    Luogu P3879 【[TJOI2010]阅读理解】
    Luogu P2727 【01串 Stringsobits】
    CF1200D 【White Lines】
    Luogu P4945 【最后的战役】
    Luogu P4944 【PION贪吃蛇】
    Luogu P2426 【删数】
    P2163 【[SHOI2007]园丁的烦恼】
  • 原文地址:https://www.cnblogs.com/halfrot/p/7642957.html
Copyright © 2011-2022 走看看