2016年11月10日 星期四

TIOJ 1030 - Floor Machine

http://tioj.infor.org/problems/1030

greedy做事就好
為了節省樓層 所以每個樓層如果能讓兩個胖虎的歌聲都存在就好(當然那層不能有人)
所以讓大的排在一起 空隙就會比較小



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int r[100005];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    while(cin>>n && n){
        for(int i=0;i<n;i++){
            cin>>r[i];
        }
        sort(r,r+n);
        ll ans=1;
        for(int i=0;i<n;i++){
            ans+=r[i];
        }
        ans+=r[n-1];
        cout<<ans<<'\n';
    }
}

沒有留言:

張貼留言