Love丶FFC's Blog

CCF-CSP_20180301:跳一跳

2019-10-15 20:32:37
阅读:571   •   评论:3
标签:,

问题描述

近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱。

简化后的跳一跳规则如下:玩家每次从当前方块跳到下一个方块,如果没有跳到下一个方块上则游戏结束。

如果跳到了方块上,但没有跳到方块的中心则获得1分;跳到方块中心时,若上一次的得分为1分或这是本局游戏的第一次跳跃则此次得分为2分,否则此次得分比上一次得分多两分(即连续跳到方块中心时,总得分将+2,+4,+6,+8...)。

现在给出一个人跳一跳的全过程,请你求出他本局游戏的得分(按照题目描述的规则)。

输入格式

输入包含多个数字,用空格分隔,每个数字都是1,2,0之一,1表示此次跳跃跳到了方块上但是没有跳到中心,2表示此次跳跃跳到了方块上并且跳到了方块中心,0表示此次跳跃没有跳到方块上(此时游戏结束)。

输出格式

输出一个整数,为本局游戏的得分(在本题的规则下)。

样例输入

1 1 2 2 2 1 1 2 2 0

样例输出

22

数据规模和约定

对于所有评测用例,输入的数字不超过30个,保证0正好出现一次且为最后一个数字。

编程语言:Java

解题思想:

1.对几种可能的情况进行判断。

时间复杂度:O(n)

IDE代码如下:

  1. package CCF_CSP;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class _20180301_100point {
  8.  
  9. public static void main(String[] args) {
  10. Scanner scanner = new Scanner(System.in);
  11. int point = 0; //总得分
  12. int continuationjump = 0; //连续跳跃到中心的得分情况
  13.  
  14. List<Integer> jumpcondition = new ArrayList<Integer>(); //跳跃情况
  15. for(int i=0;i<30;i++)
  16. {
  17. jumpcondition.add(scanner.nextInt());
  18. if(jumpcondition.get(i) == 2) //跳跃到中心
  19. {
  20. if(i == 0) //第一次跳跃
  21. {
  22. point += 2;
  23. continuationjump += 2;
  24. }
  25. else if(jumpcondition.get(i-1) == 1) //非第一次跳跃但前一次跳跃得1分
  26. {
  27. point += 2;
  28. continuationjump += 2;
  29. }
  30. else //连续跳跃到中心
  31. {
  32. continuationjump += 2;
  33. point += continuationjump;
  34. }
  35. }
  36. else if(jumpcondition.get(i) == 1) //未跳跃到中心
  37. {
  38. point += 1;
  39. continuationjump = 0; //连续跳跃到中心点的得分清零
  40. }
  41. else //0:结束
  42. {
  43. break;
  44. }
  45. }
  46. System.out.println(point);
  47. }
  48.  
  49. }
  50.  

评论板

共有 3 条评论

  1. Abupguele

    2 tumors developed bone metastases overnight cialis delivery The young elf girl s voice came from outside the bedroom, and they expressed their apologies in horror and respect, and said they wanted to leave immediately

  2. invoimi

    side effects of propecia Vitamin D plays a physiologic role in reproduction including ovarian follicular development and luteinisation, follicle- stimulating hormone sensitivity and progesterone production in human granulosa cells

  3. jXEviou

    Androgen deprivation therapy for prostate cancer and osteoporotic risk where to buy cialis

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:498325