a084: Complaint Value of a Queue 排隊抱怨值
標籤 : Strings
通過比率 : 100% (4 人 / 4 人 ) (非即時)
評分方式 :
Tolerant

最近更新 : 2020-04-16 08:54

內容

People need to spend time lining up when entering some popular performance venue. Assume each one in the line of entering a performance venue is assigned a sequential number. One with a smaller sequential number is supposed to have a higher priority to enter the place. For example, if someone’s number is 1, then he should be the first to enter. However, some people with the lower priority might cut in the line, and it makes the law-abiding people complain.

 

Suppose everyone in the line queue has a complaint value 0 initially. For a person in the queue, if the people in line ahead of him all have greater priority than him, the final complaint value is 0. Else if k people in line ahead of him with priorities lower than him, his compliant value increases by k. The compliant value of a queue is the sum of the values of all individuals.

 

Please calculate the complaint value of the given line queue.

 

參加熱門的演唱會或週年慶的百貨公司等一些熱門活動,因人數眾多,常常需要要排隊進場。假設在進場的排隊隊伍中,每個人都有一個順序號碼,而號碼較小的消費者擁有較高的優先權進場。比方說,如果有人拿到的的順序號碼是1,那麼他應該可以第一個進場。然而,當隊伍有人插隊時,低優先權的人會排在高優先權的前面,這會激起守法的排隊者的抱怨。

 

假設隊伍中每個人都有一個起始值為0的抱怨值。若排在他前面的人,其優先權都比他大,則抱怨值保持為0;而當他前面有k個優先權比他低的人插隊進來時,則他的抱怨值增加k。一個排隊隊伍的抱怨值設為所有排隊人員的抱怨值總和。

 

請計算排隊隊伍的抱怨值。

輸入說明
  1. An integer N means the number of people in a line queue, 0 < N < 100.
  2. N sequential numbers Si, i = 1,..,N and 0 < Si < 10000.

 

  1. 整數N(排隊人數)。(0 < N <100)
  2. 隊伍中每個人的順序號碼Si,i = 1,...,N且 0 < Si < 10000。
輸出說明

Output the compliant value of the line queue with the format “Complaint =X.”

 

輸出排隊隊伍的抱怨值,其格式為“Complaint=X”。

範例輸入
8
1
20
54
1
50
100
200
50
範例輸出
Complaint=6
測資資訊 :
記憶體限制 : 64 MB
隱藏 測資點#0 (33%): 3.0s , <1K
隱藏 測資點#1 (33%): 3.0s , <1K
隱藏 測資點#2 (34%): 3.0s , <1K
提示 :
標籤:
Strings
出處:
ITSA 教育部智慧創新跨域人才培育計畫 [編輯 :
zero_jason (zero_jason(MANAGER))
]


編號 身分 題目 主題 人氣 發表日期
沒有發現任何「解題報告」