Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
被打败了,贴个没有过的代码吧,请教高手们还有很么可以优化的地方么,还是因为用了stl所以慢#include <vector> #include <iostream> #include <algorithm> using namespace std; struct Three { int first, second, third; Three(const int &f, const int &s, const int &t ) { first = f; second = s; third = t; } }; struct Three_Comp { bool operator() (Three &op1, Three &op2) const { return op1.second < op2.second; } }; int main() { int k; cin >> k; int i; vector<Three> h; h.clear(); int h_i, a_i, c_i; for( i = 0; i < k; i++ ) { cin >> h_i >> a_i >> c_i; h.push_back(Three(h_i,a_i,c_i)); } sort(h.begin(), h.end(), Three_Comp()); bool bucket[40001]; memset(bucket,0,sizeof(bucket)); vector<int> height; bucket[0] = true; height.push_back(0); int max = 0; for( i = 0; i < h.size(); i++ ) { int t = height.size(); for( int j = 0; j < t; j++ ) { if ( height[j] + h[i].first > h[i].second ) break; for( int l = 1; l <= h[i].third; l++ ) { int temp = height[j] + h[i].first * l; if ( temp <= h[i].second ) { if ( bucket[temp] == false ) { bucket[temp] = true; height.push_back(temp); if ( temp > max ) max = temp; } } else break; } } } cout << max << endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator