zoukankan      html  css  js  c++  java
  • 烟大 Contest1025

    Problem A: Jolly Jumpers

    Time Limit: 1 Sec  Memory Limit: 64 MB
    Submit: 10  Solved: 4
    [Submit][Status][Web Board]

    Description

    A sequence of n > 0 integers is called a jolly jumper if the absolute values of the differences between successive elements take on all possible values 1 through n - 1. For instance, 1 4 2 3 is a jolly jumper, because the absolute differences are 3, 2, and 1, respectively. The definition implies that any sequence of a single integer is a jolly jumper. Write a program to determine whether each of a number of sequences is a jolly jumper.

    Input

    Each line of input contains an integer n < 3, 000 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

     

    HINT

    poj2575


     

      水题。

      这道题要求输入一串整型数,第一个数为n,后面接着有n个int数,要求后面这n个数两两之间差的绝对值在[1,n-1]范围内,且差的绝对值不能重复。

      虽是水题,但还是纠结了一会,原因还是没有读懂题意,忽略了第二个条件。由此可见,英语阅读能力的重要性!

    My code:

     1 #include <iostream>
     2 
     3 using namespace std;
     4 
     5 int abs(int n)
     6 {
     7     return n>0?n:-n;
     8 }
     9 int main()
    10 {
    11     int n;
    12     int ab;
    13     int i;
    14     int a[3000];  
    15     while(cin>>n){
    16         bool b[3001]={0};   //记录绝对值差有无重复
    17         for(i=0;i<n;i++){   //输入
    18             cin>>a[i];
    19         }
    20         for(i=1;i<n;i++){    //循环判断
    21             int t=abs(a[i]-a[i-1]);
    22             if(!(1<=t && t<=n-1) || b[t] )
    23                 break;
    24             else{
    25                 b[t]=true;
    26             }
    27         }
    28         if(i==n)    //如果正常跳出,说明是个Jolly
    29             cout<<"Jolly"<<endl;
    30         else{
    31             cout<<"Not jolly"<<endl;
    32         }
    33     }
    34     return 0;
    35 }

     

     Freecode : www.cnblogs.com/yym2013

  • 相关阅读:
    开源项目
    获取手机剩余空间工具类
    圆形图片
    gridview添加header
    Eclipse中10个最有用的快捷键组合
    那些年不错的Android开源项目(转)
    Android 获取系统或SDCARD剩余空间信息(转)
    android之 Activity跳转出现闪屏
    解决Activity启动黑屏及设置android:windowIsTranslucent不兼容activity切换动画问题
    Android studio 导入工程 出现错误
  • 原文地址:https://www.cnblogs.com/yym2013/p/3232193.html
Copyright © 2011-2022 走看看