Codeforces Round #204 (Div. 2): B

很简单的一个题;

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

代码:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define maxn 100005
 4 using namespace std;
 5 
 6 int n,x;
 7 int a[maxn][2],cot;
 8 struct node
 9 {
10     int v,id;
11     bool operator<(node const &t)const
12     {
13         if(v==t.v)return id<t.id;
14         return v<t.v;
15     }
16 } no[maxn];
17 
18 int main()
19 {
20     scanf("%d",&n);
21     for(int i=1; i<=n; i++)
22     {
23         scanf("%d",&x);
24         no[i].v=x;
25         no[i].id=i;
26     }
27     sort(no+1,no+n+1);
28     for(int i=1; i<=n;)
29     {
30         int t=no[i].v;
31         if(no[i+1].v!=t)
32         {
33             a[cot][0]=no[i].v;
34             a[cot][1]=0;
35             cot++;
36             i++;
37         }
38         else
39         {
40             int d=no[i+1].id-no[i].id;
41             while(1)
42             {
43                 i++;
44                 if(no[i+1].v!=t)
45                 {
46                     a[cot][0]=t;
47                     a[cot][1]=d;
48                     cot++;
49                     i++;
50                     break;
51                 }
52                 if(no[i+1].id-no[i].id!=d)
53                 {
54                     while(1)
55                     {
56                         i++;
57                         if(no[i+1].v!=no[i].v)
58                         {
59                             i++;
60                             break;
61                         }
62                     }
63                     break;
64                 }
65             }
66         }
67     }
68     printf("%d\n",cot);
69     for(int i=0;i<cot;i++)
70         printf("%d %d\n",a[i][0],a[i][1]);
71     return 0;
72 }
View Code

 

posted @ 2013-10-13 16:10  Yours1103  阅读(182)  评论(0编辑  收藏  举报