标签:tchar amp har blog class name tag zoj else
题目链接: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(‘\n‘); 42 } 43 return 0; 44 }
标签:tchar amp har blog class name tag zoj else
原文地址:http://www.cnblogs.com/halfrot/p/7642957.html