題型:簡單題
題意:
分析:
代碼:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>using namespace std;struct node{ int h,id;}x[123456];bool cmp(node a,node b){ if(a.h == b.h) return a.id < b.id; else return a.h < b.h;}int v[123456],w[123456];int main(){ int n; while(~scanf("%d",&n)){ memset(v,0,sizeof(v)); memset(w,0,sizeof(w)); for(int i=0;i<n;i++){ scanf("%d",&x[i].h); x[i].id=i; } x[n].h=9999999; x[n].id=n; n++; sort(x,x+n,cmp); /* for(int i=0;i<n;i++){ printf("%d %d\n",x[i].h,x[i].id); } cout<<endl; */ int cnt=1,iid=0,d=x[1].id-x[0].id; bool flag=true; for(int i=1;i<n;i++){ if(x[i].h!=x[i-1].h){ if(flag){ v[iid]=x[i-1].h; if(cnt==1) w[iid]=0; else w[iid]=d; iid++; } cnt=1; flag=true; d=x[i+1].id-x[i].id; } else{ if(flag){ if(d != x[i].id-x[i-1].id){ flag=false; continue; } else cnt++; } } } printf("%d\n",iid); for(int i=0;i<iid;i++){ printf("%d %d\n",v[i],w[i]); } } return 0;}