zoukankan      html  css  js  c++  java
  • E

    E - Jolly Jumpers
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Submit Status

    Description

    A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,

    1 4 2 3
    

    is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.

    Input

    Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.

    Output

    For each line of input, generate a line of output saying "Jolly" or "Not jolly".

    Sample Input

    4 1 4 2 3
    5 1 4 2 -1 6

    Sample Output

    Jolly
    Not jolly

    难懂的题意。。(被题意坑了一发QAQ)

    首先输入一个正整数n,后接n个数字,每连续的两个数字相减的绝对值组成1~n-1共n-1个数字。

    AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<cstdlib>
     7 using namespace std;
     8 
     9 const int MAX=3050;
    10 int a[MAX];
    11 int b[MAX];
    12 int n;
    13 int main(){
    14     while(~scanf("%d",&n)){
    15         for(int i=0;i<n;i++){
    16             scanf("%d",&a[i]);
    17         }
    18         if(n==1){//当n为1时直接输出 
    19             printf("Jolly
    ");
    20             continue;
    21         }
    22         for(int i=1;i<n;i++){//两两相减的绝对值 
    23             b[i]=abs(a[i]-a[i-1]);
    24         }
    25         int temp;
    26         for(int i=1;i<n;i++){//冒泡排序 
    27             for(int j=n-1;j>=i;j--){
    28                 if(b[j]<b[j-1]){
    29                     temp=b[j];
    30                     b[j]=b[j-1];
    31                     b[j-1]=temp;
    32                 }
    33             }
    34         }
    35         int ans=0;
    36         for(int i=1;i<n;i++){//记录相等数字数 
    37             if(b[i]==i)
    38             ans++;
    39         }
    40         if(ans==n-1)
    41         printf("Jolly
    ");
    42         else
    43         printf("Not jolly
    ");
    44     }
    45     return 0;
    46 } 
  • 相关阅读:
    poj-1069(三角形和六边形)(转)
    poj-1024(唯一最短路径)(转)
    poj-1022(四维模仿)(转)
    poj-1020(填蛋糕)(转)
    poj-1011
    poj-1010(转)
    poj-2312
    nyoj--幸运三角形
    nyoj--Divideing Jewels
    关于 APP在接入flutter之后在多任务下看不到AppName,只有APP图标,正常应该是APP图标+APP名称
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5513790.html
Copyright © 2011-2022 走看看