Last active
August 29, 2015 14:04
-
-
Save cocodrips/7f2ccfaa1fe6709444cb to your computer and use it in GitHub Desktop.
SRM620 Div1 Easy in C++ PairGame
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
#include <cstdio> | |
#include <cmath> | |
#include <cstring> | |
#include <ctime> | |
#include <iostream> | |
#include <algorithm> | |
#include <set> | |
#include <vector> | |
#include <map> | |
#include <tuple> | |
#include <sstream> | |
#include <typeinfo> | |
#include <fstream> | |
using namespace std; | |
class PairGame { | |
public: | |
vector<vector<int> > parts(int a, int b){ | |
vector<vector<int> > sums(2000000); | |
sums[a+b] = {a,b}; | |
while(a > 0 and b > 0){ | |
if (a > b) { | |
a = a - b; | |
} else { | |
b = b - a; | |
} | |
sums[a+b] = {a,b}; | |
} | |
return sums; | |
} | |
int maxSum(int a, int b, int c, int d) { | |
auto sumsA = parts(a, b); | |
auto sumsC = parts(c, d); | |
for (int i = sumsA.size() - 1; i >= 0; --i){ | |
if (!sumsC[i].empty()){ | |
if (sumsA[i] == sumsC[i]){ | |
return i; | |
} | |
} | |
} | |
return -1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment