SGU,sguonline

來源:互聯網
上載者:User

SGU,sguonline

186. The Chaintime limit per test: 0.25 sec.
memory limit per test: 4096 KBinput: standard input
output: standard output


Smith has N chains. Each chain is the sequence of successively connected links. The length of each chain is known: the first chain contains L1 links, the second - L2, ..., the last one - LN. 
He can make a following series of actions in a minute: 
1. to unchain one link 
2. to remove or to put into the unchained link some other links of any chain 
3. to chain the link 
Your task is to determine the minimum time which will take the smith to connect all the chains in one line, i.e. the chain will look like a chain made up of successively connected links.
InputThe first line contains natural number N<=100. The second line contains L1, L2, ..., LN (1<=Li<=100, for all i = 1..N).
OutputOutput the only integer number - the solution to the problem.
Sample test(s)
Input
2 3 4Output
1[submit][forum]
Author: Michael R. Mirzayanov
Resource: ACM International Collegiate Programming Contest 2003-2004 
North-Eastern European Region, Southern Subregion
Date: 2003 October, 9











思路:好無恥的英語,說的這麼拐彎抹角真的好嗎?題意應該是這樣的,先從一個chain上拆下一個link,然後可以串連兩個chain,只到所有chain都連起來為止,這裡算一分鐘,所以先從短鏈開始拆更省時,貪心....


AC代碼:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[105];int main() {int n;while(scanf("%d", &n) != EOF) {for(int i = 0; i < n; i++) {scanf("%d", &a[i]);}sort(a, a+n);int i = 0, j = n-1, ans = 0;while(i < j) {a[i]--;j--;if(a[i] == 0) i++;ans++;}printf("%d\n", ans);}return 0;} 











聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.