poj解题报告——poj 2575 Jolly Jumpers

原题入口

poj 2575 Jolly Jumpers

题目描述

Jolly Jumpers
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17683 Accepted: 5348

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

Source
Waterloo local 2000.09.30

解题代码

#include <iostream>
#include <cmath>
using namespace std;

#define SEQUENCE_COUNT  3000
char flag[SEQUENCE_COUNT] = {0};

int main()
{
    int N;                  // 序列中数字的个数
    int nNum, nNextNum;     // 连续的两个数字

    while ((cin >> N) && N)
    {
        cin >> nNum;
        if (N == 1)
        {
            cout << "Jolly" << endl;
            continue;
        }

        memset(flag, 0, sizeof(flag));
        for (int nIndex = 2; nIndex <= N; ++nIndex)
        {
            cin >> nNextNum;
            int nDiff = abs(nNextNum - nNum);
            if (nDiff < SEQUENCE_COUNT)
                flag[nDiff] = 1;

            nNum = nNextNum;
        }

        int nFlagIndex = 1;
        for (; nFlagIndex < N; ++nFlagIndex)
        {
            if (flag[nFlagIndex] <= 0)
            {
                cout << "Not jolly" << endl;
                break;
            }
        }

        if (nFlagIndex == N)
            cout << "Jolly" << endl;
    }

    return 0;
}

解题过程

  • 题意:每行开头给你一个正整数n,后面紧跟n个数组成的序列,序列中连续两个数字作差求绝对值,如果所有的绝对值占满了[1,n-1]之间的所有数字,则输出”Jolly”,否则输出”Not jolly”,值的注意的是,根据定义,任何一个单个的数字都是”Jolly Jumpers”。

  • 思路:做一个标记数组就解决战斗乐,作差的过程中,将绝对值对应的数组位置设置成1,一行结束后遍历数组即可得出结果

  • 槽点:这个问题得好好说一下,通过率才30%,我怀着忐忑的心情一遍水过,下面说说为啥会忐忑:

    1.注意题目中的一个单词successive,这个词居然达到了专家级难度,它的意思是连续的,也就是作差需要相邻的两个数来做。
    2.The definition implies that any sequence of a single integer is a jolly jumper.这一句需要注意到,否则WA。
    3.说到n==1时输出”Jolly”,有人却说这样写会报错,不写的话通过了,我看到这都凌乱了,我只想说我是这样写的才通过,那种不考虑n==1的情况我没试,不想降低概率。
    4.还有一点需要注意的是,n==1时后面还有一个数字别忘了读,否则就出错了。
    5.就是因为发现这些坑和这么低的AC率我才忐忑的提交,结果一遍过了。。。

提交结果

poj2575

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AlbertS

常来“玩”啊~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值