Last active
December 18, 2015 01:28
-
-
Save yongpitt/5704009 to your computer and use it in GitHub Desktop.
Theme Park Solution (Google Code Jam Qualification Round 2010)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Theme Park Solution (Google Code Jam Qualification Round 2010)*/ | |
| //I coded this program in 1 and half hour and it took me another 30 minutes to debug and pass all the tests. | |
| //For problem description and tests go to https://code.google.com/codejam/contest/dashboard?c=433101#s=p2 | |
| void ThemePark::PrintRevenue(ifstream &infile) | |
| { | |
| int T, R, k, N; | |
| ofstream outfile("D:/tests/output.out"); | |
| infile >> T; | |
| for(int i=1; i<=T; i++){ | |
| infile >> R >> k >> N; | |
| vector<long long int> rev1(N,0); | |
| vector<long long int> rev2(N,0); | |
| vector<long long int> rn1(N,0); | |
| vector<long long int> rn2(N,0); | |
| vector<int> groups(N,0); | |
| for(int j=0; j<N; j++) | |
| infile >> groups[j]; | |
| long long int sum = 0; | |
| int currIdx = 0; | |
| for(int r=1; r<=R; r++){ | |
| int people = 0; | |
| for(int g=0; g<N; g++){ | |
| people += groups[currIdx]; | |
| currIdx = (currIdx+1)%N; | |
| if(g+1==N || people+groups[currIdx]>k) | |
| break; | |
| } | |
| sum += people; | |
| if(rev1[currIdx] == 0){ | |
| rev1[currIdx] = sum; | |
| rn1[currIdx] = r; | |
| } | |
| else if(rev2[currIdx] == 0){ | |
| rev2[currIdx] = sum - rev1[currIdx]; | |
| rn2[currIdx] = r - rn1[currIdx]; | |
| } | |
| if(rev2[currIdx] != 0){ | |
| sum += rev2[currIdx]*((R-r)/rn2[currIdx]); //I previously put these two statements in the wrong order. | |
| r += rn2[currIdx]*((R-r)/rn2[currIdx]); //Apparently that was wrong since we want to use the old r | |
| } | |
| } | |
| outfile << "Case #" << i <<": " << sum << endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment