SRM 591 div1 275

   topcoder被Appirio收購了ios

  很久沒作tc,這個題目挺簡單。就是Arena裏面看不到圖片,只能去tc網站上找題目。http://community.topcoder.com/stat?c=problem_statement&pm=12746ide

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int tmp[55];
class TheTree {
public:
    int maximumDiameter(vector <int> cnt) {
        int D = cnt.size(), i, j;
        int ans = 0, sum;
        
        for(i = 0; i < D; ++i) {
            for(j = i; j < D; ++j)    tmp[j] = cnt[j];
            sum = 0;
            for(j = i; j < D; ++j) {
                if(tmp[j] != 0) {
                    tmp[j]--;
                    sum++;
                } else break;
            }
            for(j = i; j < D; ++j) {
                if(tmp[j] != 0) {
                    tmp[j]--;
                    sum++;
                } else break;
            }
            printf("%d\n", sum);
            ans = max(ans, sum);
        }
        return ans;
    }
};


<%:testing-code%>
//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
View Code
相關文章
相關標籤/搜索