zoukankan      html  css  js  c++  java
  • AC日记——有趣的跳跃 openjudge 1.6 07

    07:有趣的跳跃

    总时间限制: 
    1000ms
     
    内存限制: 
    65536kB
    描述

    一个长度为n(n>0)的序列中存在“有趣的跳跃”当前仅当相邻元素的差的绝对值经过排序后正好是从1到(n-1)。例如,1 4 2 3存在“有趣的跳跃”,因为差的绝对值分别为3,2,1。当然,任何只包含单个元素的序列一定存在“有趣的跳跃”。你需要写一个程序判定给定序列是否存在“有趣的跳跃”。

    输入
    一行,第一个数是n(0 < n < 3000),为序列长度,接下来有n个整数,依次为序列中各元素,各元素的绝对值均不超过1,000,000,000。
    输出
    一行,若该序列存在“有趣的跳跃”,输出"Jolly",否则输出"Not jolly"。
    样例输入
    4 1 4 2 3
    
    样例输出
    Jolly
    
    来源
    Waterloo local 2000.09.30

    思路:

      模拟;

    来,上代码:

    #include<cmath>
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    
    using namespace std;
    
    int n;
    
    long long int ai[3001],bi[3001];
    
    int main()
    {
        scanf("%d",&n);
        if(n==1)
        {
            printf("Jolly
    ");
            return 0;
        }
        for(int i=1;i<=n;i++) scanf("%lld",&ai[i]);
        for(int i=1;i<n;i++) bi[i]=abs(ai[i+1]-ai[i]);
        sort(bi+1,bi+n);
        for(int i=1;i<n;i++) 
        {
            if(bi[i]!=i)
            {
                printf("Not jolly
    ");
                return 0;
            }
        }
        printf("Jolly
    ");
        return 0;
    }
  • 相关阅读:
    Mysql系列【解决mysql连接数太多】
    并发编程系列【线程池七大核心参数】
    C信号处理的基础
    设计模式之Command
    Ext文件系统
    内存管理
    设计模式之Decorator Pattern
    设计模式之singleton
    Quicklz压缩算法
    设计模式之Factory
  • 原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6130263.html
Copyright © 2011-2022 走看看