Created
March 21, 2018 03:33
-
-
Save YiqinZhao/36ec0a9f09cbbaaf9a26628f5b2ec1c0 to your computer and use it in GitHub Desktop.
[Lemo Puzzle] Two array, boxes and lemos stand for size of boxes and size of lemos. Every lemo can be put into a box which has equal or bigger size. Pick a start point i from lemos array, find a possible box and repeat this action for i+1, i+2. All lemos in boxes should keep their original orders. What is the longest sequence of lemos in boxes. …
This file contains 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
#include <iostream> | |
int boxes[10] = {5, 3, 2, 7, 10, 9, 1, 6, 4, 8}; | |
int lemons[10] = {2, 6, 7, 1, 10, 5, 4, 3, 9, 8}; | |
int main() { | |
int globalMax = -1; | |
for (int k = 0; k < 10; k++) { | |
int i = k, j = 0; | |
std::cout << "Current: " << i << std::endl; | |
for (int m = 0; m < 10; m++) std::cout << boxes[m] << ' '; | |
std::cout << std::endl; | |
while (i < 10 && j < 10) { | |
if (lemons[i] <= boxes[j]) { | |
std::cout << lemons[i] << ' '; | |
i++; | |
} else { | |
std::cout << " "; | |
} | |
j++; | |
} | |
int localMax = i - k; | |
globalMax = globalMax < localMax ? localMax : globalMax; | |
std::cout << std::endl << "--> Max length: " << localMax; | |
std::cout << std::endl << std::endl; | |
} | |
std::cout << std::endl << "--> Global Max: " << globalMax << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment