Love丶FFC's Blog

CCF-CSP_20180901:卖菜

2019-10-17 21:50:56
阅读:1259   •   评论:10
标签:,

问题描述

在一条街上有n个卖菜的商店,按1至n的顺序排成一排,这些商店都卖一种蔬菜。

第一天,每个商店都自己定了一个价格。店主们希望自己的菜价和其他商店的一致,第二天,每一家商店都会根据他自己和相邻商店的价格调整自己的价格。具体的,每家商店都会将第二天的菜价设置为自己和相邻商店第一天菜价的平均值(用去尾法取整)。

注意,编号为1的商店只有一个相邻的商店2,编号为n的商店只有一个相邻的商店n-1,其他编号为i的商店有两个相邻的商店i-1和i+1。

给定第一天各个商店的菜价,请计算第二天每个商店的菜价。

输入格式

输入的第一行包含一个整数n,表示商店的数量。

第二行包含n个整数,依次表示每个商店第一天的菜价。

输出格式

输出一行,包含n个正整数,依次表示每个商店第二天的菜价。

样例输入

8
4 1 3 1 6 5 17 9

样例输出

2 2 1 3 4 9 10 13

数据规模和约定

对于所有评测用例,2 ≤ n ≤ 1000,第一天每个商店的菜价为不超过10000的正整数。

编程语言:Java

解题思想:

1.注意第一家和最后一家商店的特别情况

2.算出第二天的平均价格

时间复杂度:O(n)

IDE代码如下:

  1. package CCF_CSP;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _20180901_100point {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int n = scanner.nextInt(); //商店菜店的数量
  10. int[] firstdayprice = new int[n]; //每家商店第一天的菜价
  11. int[] seconddayprice = new int[n]; //每家商店第二天的菜价
  12.  
  13. for(int i=0;i<n;i++)
  14. {
  15. firstdayprice[i] = scanner.nextInt(); //每家商店
  16. }
  17.  
  18. for(int i=0;i<n;i++)
  19. {
  20. if(i==0) //第一家商店
  21. {
  22. seconddayprice[i] = (firstdayprice[i]+firstdayprice[i+1])/2;
  23. System.out.print(seconddayprice[i]+" ");
  24. }
  25. else if(i==n-1) //最后一家商店
  26. {
  27. seconddayprice[i] = (firstdayprice[i]+firstdayprice[i-1])/2;
  28. System.out.print(seconddayprice[i]);
  29. }
  30. else //其余商店
  31. {
  32. seconddayprice[i] = (firstdayprice[i-1]+firstdayprice[i+1]+firstdayprice[i])/3;
  33. System.out.print(seconddayprice[i]+" ");
  34. }
  35. }
  36.  
  37. }
  38.  
  39. }
  40.  

评论板

共有 10 条评论

  1. fruinly

    cialis pills The technique presented herein offers a highly reproducible and low cost method to evaluate the bone marrow contribution to pathophysiological processes and is especially suited to carry out immune recovery strategies

  2. engarma

    generic cialis online pharmacy Closer analysis indicated peaks of testosterone secretion in the adults Wani et al

  3. Preliaf

    buying cialis online reviews Curr Opin Cell Biol 31 56 66

  4. Preliaf

    cialis order online When treating patients in primary care who meet criteria for infertility, obtain all required lab results including SA while initiating a referral to a fertility specialist

  5. BHEVRpdqg

    These findings further support the idea that AF 1 may mediate the agonistic activity of Tamoxifen buy cialis online with a prescription Open in Read by QxMD Dutta DC, Konar H

  6. Xjlpel

    tricor over the counter order tricor 160mg pills order tricor 160mg

  7. Bejmla

    purchase ketotifen for sale buy imipramine without prescription order imipramine pills

  8. Mizxpl

    cheap cialis 5mg viagra 50mg uk purchase sildenafil pills

  9. Szsmwy

    purchase acarbose sale order repaglinide generic brand fulvicin

  10. Mwozwm

    buy minoxidil generic flomax over the counter buy erectile dysfunction pills

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名: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 -

已运行:

访问量:496042