Poj 2575 jolly jumpers (simple question)

Source: Internet
Author: User

[Description]: Make a difference between two adjacent numbers in the sequence, and determine whether the absolute value is 1, 2 ,......, N-1. If yes, It is jolly; otherwise, not jolly.

[Analysis]: At the beginning, I did not look at the question carefully. When I did not see the two adjacent numbers, I thought any two were doing the difference.

After re-analyzing the problem, we solved the problem. We can use a flag array to help us store the absolute value of the difference. Finally, we only need to scan this array to see if it is from 1, 2 ,......, N-1 values correspond to each other.

For details, see the code:


// 324 K 47 Ms # include <iostream> # include <cmath> using namespace STD; int flag [30001]; int main () {int N; int A, B; int TMP; while (CIN> N) {memset (flag, 0, sizeof (FLAG); CIN> A; For (INT I = 1; I <N; I ++) {CIN> B; TMP = ABS (B-A); flag [TMP] = 1; A = B;} Int J; For (j = 1; j <n; j ++) {If (flag [J] = 0) break;} If (j = N) cout <"Jolly" <Endl; else cout <"not jolly" <Endl;} return 0 ;}


Poj 2575 jolly jumpers (simple question)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.