UVa Problem Solution: 10038 - Jolly Jumpers


Simple problem. Just record the absolute values of the differences will do the job.

Code:
  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 10038 C "Jolly Jumpers" */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <strings.h>
  10.   
  11. #define MAX 3000
  12. int table[MAX];
  13. int jolly(int seq[], int n)
  14. {
  15.   int i;
  16.   bzero(table, MAX*sizeof(int));
  17.   for (i = 0; i < n - 1; ++i) {
  18.     int d = abs(seq[i] - seq[i+1]);
  19.     if (d > n - 1 || table[d])
  20.       return 0;
  21.     else
  22.       table[d] = 1;
  23.   }
  24.   return 1;
  25. }
  26.              
  27. int main(int argc, char *argv[])
  28. {
  29. #ifndef ONLINE_JUDGE
  30.   char in[256];
  31.   char out[256];
  32.   strcpy(in, argv[0]);
  33.   strcat(in, ".in");
  34.   freopen(in, "r", stdin);
  35.   strcpy(out, argv[0]);
  36.   strcat(out, ".out");
  37.   freopen(out, "w", stdout);
  38. #endif
  39.   char *answer[] = {
  40.     "Not jolly",
  41.     "Jolly",
  42.   };
  43.   int i, n;
  44.   int seq[MAX];
  45.   while (scanf("%d", &n) != EOF) {
  46.     for (i = 0; i < n; ++i)
  47.       scanf("%d", &seq[i]);
  48.     puts(answer[jolly(seq, i)]);
  49.   }  
  50.   return 0;
  51. }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值