您的位置:首页 > 其它

Codeforces Round #204 (Div. 2): B

2013-10-13 16:10 155 查看
很简单的一个题;

只需要将他们排一下序,然后判断一下就可以了!

代码:

#include<cstdio>
#include<algorithm>
#define maxn 100005
using namespace std;

int n,x;
int a[maxn][2],cot;
struct node
{
int v,id;
bool operator<(node const &t)const
{
if(v==t.v)return id<t.id;
return v<t.v;
}
} no[maxn];

int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d",&x);
no[i].v=x;
no[i].id=i;
}
sort(no+1,no+n+1);
for(int i=1; i<=n;)
{
int t=no[i].v;
if(no[i+1].v!=t)
{
a[cot][0]=no[i].v;
a[cot][1]=0;
cot++;
i++;
}
else
{
int d=no[i+1].id-no[i].id;
while(1)
{
i++;
if(no[i+1].v!=t)
{
a[cot][0]=t;
a[cot][1]=d;
cot++;
i++;
break;
}
if(no[i+1].id-no[i].id!=d)
{
while(1)
{
i++;
if(no[i+1].v!=no[i].v)
{
i++;
break;
}
}
break;
}
}
}
}
printf("%d\n",cot);
for(int i=0;i<cot;i++)
printf("%d %d\n",a[i][0],a[i][1]);
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: