zoukankan      html  css  js  c++  java
  • 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
    ",cot);
    69     for(int i=0;i<cot;i++)
    70         printf("%d %d
    ",a[i][0],a[i][1]);
    71     return 0;
    72 }
    View Code
  • 相关阅读:
    二分搜索
    Shell 字符串处理、获取文件名和后缀名
    sqlldr使用说明
    Linux cached过高问题
    算法时间复杂度
    #if,#ifdef,#ifndef的区别
    memcpy momove strcmp源码实现
    怎么解决/bin/sh: arm-linux-gcc: not found make
    性能文章
    linux
  • 原文地址:https://www.cnblogs.com/yours1103/p/3366750.html
Copyright © 2011-2022 走看看