日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

1017 The Best Peak Shape (35 分)(最佳峰形)(思路+详解+翻译+题意分析)Come brather!!!!!!!!!

發布時間:2023/12/4 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1017 The Best Peak Shape (35 分)(最佳峰形)(思路+详解+翻译+题意分析)Come brather!!!!!!!!! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一:題目:

In many research areas, one important target of analyzing data is to find the best “peak shape” out of a huge amount of raw data full of noises. A “peak shape” of length L is an ordered sequence of L numbers { D

Now given N input numbers ordered by their indices, you may remove some of them to keep the rest of the numbers in a peak shape. The best peak shape is the longest sub-sequence that forms a peak shape. If there is a tie, then the most symmetric (meaning that the difference of the lengths of the increasing and the decreasing sub-sequences is minimized) one will be chosen.

Input Specification:
Each input file contains one test case. For each case, the first line gives an integer N (3≤N≤10
4
). Then N integers are given in the next line, separated by spaces. All the integers are in [?10000,10000].

Output Specification:
For each case, print in a line the length of the best peak shape, the index (starts from 1) and the value of the peak number. If the solution does not exist, simply print “No peak shape” in a line. The judge’s input guarantees the uniqueness of the output.

Sample Input1:

20 1 3 0 8 5 -2 29 20 20 4 10 4 7 25 18 6 17 16 2 -1

結尾無空行
Sample Output1:

10 14 25

結尾無空行
Sample Input2:

5 -1 3 8 10 20

Sample Output2:

No peak shape

二:翻譯:

在許多研究領域中,分析數據的一個重要目標就是從大量充滿噪聲的原始數據中找到最佳的“峰形”。長度為L的“峰形”是L數{D的有序序列

現在給定N個輸入數字,按照它們的索引排序,你可以刪除其中的一些數字,以保持其余數字的峰值形狀。最佳峰形是形成峰形的最長子序列。如果有一個平局,那么將選擇最對稱的(即增加子序列和減少子序列的長度之差是最小的)一個。

輸入規格:

每個輸入文件包含一個測試用例。對于每種情況,第一行給出整數N(3≤N≤10)

4

). 然后在下一行給出N個整數,用空格隔開。所有整數的取值范圍為[?10000,10000]。

輸出規范:

對于每種情況,在一行中打印最佳峰值形狀的長度、索引(從1開始)和峰值數的值。如果不存在解決方案,只需在一行中打印“無峰形”。法官的輸入保證了輸出的唯一性。

示例Input1:

20.1 3 0 8 5 -2 29 20 20 4 10 4 7 25 18 6 17 16 2 -1

結尾無空行

示例Output1:

10 14 25

結尾無空行

示例Input2:

51 3 8 10 20

示例Output2:

No peak shape

三:分析題意+思路

分析題意:1.想要求一個帶有峰值的 最長峰形,即峰值前面的數小于峰值,
峰值后面的數小于峰值
2.如果出現長度一樣的峰型,則考慮比較對稱的峰形,
即峰值左右數的個數相差比較少的

思路:我們要求的結果的過程是動態的也就是在變化,所以這類題是動態規劃
統計每個數值的最佳峰形長度,最后求出最大值
那么在統計每個數值的峰形長度 = 數值前面比起小的個數 + 本身(1)+ 后面比起大的數

下標為 i 的數值 前面比起小的數
m_first[i] = max(m_first[i],m_first[前面的數] + 1),這里加一是表示統計第一次前面有數比起小的時候為1

下標為 i 的數值 后面比起小的數

m_last[i] = max(m_last[i],m_last[后面的數] + 1)

四:上碼

/**分析題意:1.想要求一個帶有峰值的 最長峰形,即峰值前面的數小于峰值,峰值后面的數小于峰值 2.如果出現長度一樣的峰型,則考慮比較對稱的峰形,即峰值左右數的個數相差比較少的思路:我們要求的結果的過程是動態的也就是在變化,所以這類題是動態規劃 統計每個數值的最佳峰形長度,最后求出最大值那么在統計每個數值的峰形長度 = 數值前面比起小的個數 + 本身(1)+ 后面比起大的數下標為 i 的數值 前面比起小的數 m_first[i] = max(m_first[i],m_first[前面的數] + 1),這里加一是表示統計第一次前面有數比起小的時候為1下標為 i 的數值 后面比起小的數m_last[i] = max(m_last[i],m_last[后面的數] + 1) */ #include<bits/stdc++.h> using namespace std;int main(){int m_first[10010];//存的是m[i] 前面比起小的個數 int m_last[10010]; //存的是m[i] 后面比起小的個數 int m[10010];// 存放的輸入的數值memset(m_first,0,sizeof(m_first));memset(m_last,0,sizeof(m_last));memset(m,0,sizeof(m));int N;cin >> N;for(int i = 1; i <= N; i++){cin >> m[i];}//統計 峰值 前面的遞增的序列當中的數個數for(int i = 1; i <= N; i++){for(int j = 1; j <= i - 1; j++){if(m[j] < m[i])m_first[i] = max(m_first[i],m_first[j] + 1);//這里的每次更新,會將有的數值均前面比起大的 也就是m_first[i] = 0,那么后面的數統計到這時候會均比0大}} //從后往前 也就是峰值后面的遞減序列for(int i = N; i >= 1; i--){for(int j = N; j >= i + 1; j--){if(m[j] < m[i]){m_last[i] = max(m_last[i],m_last[j] + 1); }}} //開始統計不同下標下的個數 int max = 0;for(int i = 1; i <= N; i++){int temp = m_first[i] + m_last[i];int maxx = m_first[max] + m_last[max];if(m_first[i] == 0 || m_last[i] == 0)//如果出現遞增或遞減序列 那么其m_last[i] == 0, m_first[i] == 0;continue;else if(temp > maxx)max = i;//這種情況就是 長度一致,我們要選擇更加對稱的 else if(temp == maxx && (abs(m_first[i] - m_last[i])) < (abs(m_first[max] - m_last[max])) )max = i; } //如果出現遞增或是遞減的序列則 m_first[max] + m_last[max] == 0; if(m_first[max] + m_last[max] > 0){ cout << m_first[max] + 1 + m_last[max] << ' ' << max << ' ' << m[max]; }else{cout << "No peak shape";} }

加油陌生人,我們共勉!如有疑問歡迎留言!!!!!!!

總結

以上是生活随笔為你收集整理的1017 The Best Peak Shape (35 分)(最佳峰形)(思路+详解+翻译+题意分析)Come brather!!!!!!!!!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。