『ACM C++』 Codeforces | 1003C - Intense Heat

来源:https://www.cnblogs.com/winniy/archive/2019/03/03/10468118.html
-Advertisement-
Play Games

今日興趣新聞: NASA 研製最強推進器,加速度可達每秒 40 公裡,飛火星全靠它 鏈接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7B"nid"%3A"news_11707429683828231737"%7D&n_type ...


今日興趣新聞:

NASA 研製最強推進器,加速度可達每秒 40 公裡,飛火星全靠它

鏈接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7B"nid"%3A"news_11707429683828231737"%7D&n_type=0&p_from=1

 

 

------------------------------------------------題目----------------------------------------------------------

The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.

Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:

Suppose we want to analyze the segment of nn consecutive days. We have measured the temperatures during these nn days; the temperature during ii-th day equals aiai.

We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day xx to day yy, we calculate it as i=xyaiyx+1∑i=xyaiy−x+1 (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than kkconsecutive days. For example, if analyzing the measures [3,4,1,2][3,4,1,2] and k=3k=3, we are interested in segments [3,4,1][3,4,1], [4,1,2][4,1,2] and [3,4,1,2][3,4,1,2] (we want to find the maximum value of average temperature over these segments).

You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task?

Input

The first line contains two integers nn and kk (1kn50001≤k≤n≤5000) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively.

The second line contains nn integers a1a1, a2a2, ..., anan (1ai50001≤ai≤5000) — the temperature measures during given nn days.

Output

Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than kkconsecutive days.

Your answer will be considered correct if the following condition holds: |resres0|<106|res−res0|<10−6, where resres is your answer, and res0res0 is the answer given by the jury's solution.

input

4 3
3 4 1 2

output

2.666666666666667

------------------------------------------------題目----------------------------------------------------------

 

(一) 題目分析:

    正常div3難度題型,難度處理可能是在求和統計上,題目大概含義就是:

    求n個數中至少連續k個數的平均值的最大值,如:n=4,k=3   給定的n個數是3 4 1 2,則求[3,4,1],[4,1,2],[3,4,1,2]三個區間的平均值的最大值。

    我用的方法比較簡單,就是簡單的取值求和,今天下午打完題之後這道題還特地搜了一下,發現還有其他的解法:首碼和 /  尺縮

 

(二)AC代碼:

    因為代碼比較簡單,依舊不分塊了~

#include<stdio.h>
#define max(a,b) (a>b) ? a : b
using namespace std;
int n,k,sum;
int temp[5001];
double ans,all;
int main()
{
    scanf("%d%d",&n,&k);
    ans = 0;
    for(int i = 1;i<=n;i++) scanf("%d",&temp[i]);

    for(int i = 1;i<=n;++i)
    {
        sum = 0;
        for(int j = i;j<=n;++j)
        {
            sum+= temp[j];
            if (j - i + 1 >= k) 
            {
                all = sum * 1.0 / (j - i + 1);
                if(all>ans) ans = all;
            }
        }
    }
    printf("%.15f\n",ans);
    return 0;
}

 

(三)AC截圖:

 

 

(四)解後分析:

  貢獻一個隊內牛逼師兄高效率的代碼:

  備註一下:首碼和


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 題意 "題目鏈接" Sol 居然出個SAM板子也是沒誰了233 cpp include define Pair pair define MP(x, y) make_pair(x, y) define fi first define se second // define int long long ...
  • "知乎原鏈" 相關問題: "哪些Java庫有中文命名的API?" 且記下隨想. 之前沒有發佈過, 看了SO上的推薦: "Publish a library to maven repositories" 決定在sonatype發佈. sonatype發佈開源軟體庫的 "步驟" 寫的蠻詳細, 不過一些細 ...
  • 1、 "官網" 下載 2、雙擊開始安裝,一直下一步 用舊版的密碼加密 自己寫個密碼,最少8位 3、測試 打開系統偏好設置 4、mysql需要在系統環境變數里 1)在終端輸入 ,沒有指令說明。此時就還不能用命令或者IDE使用資料庫 2)進入存放系統命令的文件夾, 3)類似配置Java的環境變數, 4) ...
  • 一,學習背景 1. 前言 對於我們不管工作還是生活中,需要或者想去學習一些東西的時候,大致都考慮幾點: a) 我們為什麼需要學習這個東西? b) 這個東西是什麼? c) 這個東西能為我們做什麼? d) 如何去學? 結合以上幾點,我們一起學習下Dubbo這個框架! 2. 學習背景 互聯網的發展,網站應 ...
  • 這小節的題目看起來還挺晦澀的, crosstab 是 pandas 的一個函數, 作用還蠻強大的, 一起來看一下吧~~~ 首先還是先引入一個例子文件: 輸出:好, 下麵看一下 crosstab 的功力: 輸出:crosstab 第一個參數是列, 第二個參數是行. 還可以添加第三個參數: 輸出: 同時 ...
  • 首先是一個views函數的例子 def get_user_profiles(request): if request.method == 'POST': myFile = request.FILES.get("filename", None) if myFile: dir = os.path.joi ...
  • 學號 20175223 《Java程式設計》第1周學習總結 教材學習內容總結 第一章要點: 要點1:Java的三大平臺:Java SE,Java EE,Java ME。 要點2:Java的特點:簡單,面向對象,平臺無關,多線程,動態。 要點3:Java程式的開發步驟:編寫源文件,編譯源文件,運行程式 ...
  • 1、 "官網" 下載 2、把下載的文檔解壓,放到合適的路徑下。 3、打開eclipse 4、在Apache文件夾下選擇Tomcat的對應版本 5、選擇剛纔下載的文件 6、可以右鍵Start了 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...