Last active
September 26, 2015 08:36
-
-
Save Agnishom/21461359109983893a91 to your computer and use it in GitHub Desktop.
ZCO Challenges
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
//ZCO 2015 Morning Session Problem 1 | |
//Problem Statement: http://www.iarcs.org.in/inoi/2015/zco2015/zco2015-morning.pdf | |
#include <iostream> | |
bool isPallindrome(int *nNumbers, int iii, int jjj); | |
int main(){ | |
int N; | |
std::cin >> N; | |
int *nNumbers = new int[N]; | |
for (int iii = 0; iii < N; iii++){ | |
std::cin >> nNumbers[iii]; | |
} | |
int *nGroups = new int[N]; //nGroup[i] gives the group in which i is | |
int *nMembers = new int[N] {0}; //nMembers[i] gives the number of members in group i | |
int nGroupLabel; | |
for (int iii = 0; iii < N; iii++){ | |
for (int jjj = 0; jjj < iii; jjj++){ | |
if ( isPallindrome(nNumbers, iii, jjj) && ((iii - jjj + 1) > nMembers[jjj]) ){ | |
nGroupLabel = (nGroups[jjj] == 0) ? 0 : (nGroups[jjj - 1] + 1); | |
for (int kkk = jjj; kkk <= iii; kkk++) | |
nGroups[kkk] = nGroupLabel; | |
nMembers[nGroupLabel] = (iii - jjj); | |
} | |
} | |
nGroups[iii] = nGroupLabel; | |
nGroupLabel++; | |
nMembers[nGroupLabel]++; | |
} | |
std::cout << nGroups[N-1]+1; //The number of groups is the answer | |
return 0; | |
} | |
bool isPallindrome(int *nNumbers, int iii, int jjj){ | |
for (; iii >= jjj; iii--,jjj++){ | |
if (nNumbers[iii] != nNumbers[jjj]) | |
return false; | |
} | |
return true; | |
} |
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
//ZCO 2015 Afternoon Problem | |
//Problem Statement: http://www.iarcs.org.in/inoi/2015/zco2015/zco2015-afternoon.pdf | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
typedef std::pair<int,int> ii; | |
typedef std::vector<int> vi; | |
typedef std::vector<ii> vii; | |
bool compare (const ii& lhs, const ii& rhs) | |
{ | |
return lhs.second<rhs.second; | |
} | |
int main(){ | |
int N; | |
std::cin >> N; | |
vii viiIntervals; | |
int nA, nB; | |
for (int iii=0; iii < N; iii++) | |
{ | |
std::cin >> nA >> nB; | |
viiIntervals.push_back(std::pair<int,int>(nA,nB)); | |
} | |
std::sort(viiIntervals.begin(),viiIntervals.end(),compare); | |
vi viChoice; | |
int nTemp; | |
while(viiIntervals.size()){ | |
nTemp = viiIntervals.begin()->second; | |
viChoice.push_back(nTemp); | |
for (vii::iterator it=viiIntervals.begin(); | |
it != viiIntervals.end(); | |
((nTemp>=it->first) && (nTemp<=it->second)) ? viiIntervals.erase(it) : it++); | |
} | |
std::cout << viChoice.size(); | |
return 0; | |
} |
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
//ZCO 2013 Session 2 Problem 2 | |
//Problem Statement: http://www.iarcs.org.in/inoi/2014/zco2014/zco2014-2b.php | |
#include <iostream> | |
#include <algorithm> | |
int main(){ | |
int N; | |
std::cin >> N; | |
int *nFees = new int[N]; | |
for (int iii=0; iii < N; iii++) | |
std::cin >> nFees[iii]; | |
int *nBest = new int[N]; | |
nBest[0] = nFees[0]; nBest[1] = nFees[1] + nBest[0]; nBest[2] = nFees[2] + std::max({nFees[0],nFees[1]}); | |
for (int iii=3; iii < N; iii++) | |
nBest[iii] = std::max({nBest[iii-1], //either do not play this match, | |
nFees[iii] + nBest[iii-2], //or play this match but not the last one | |
nFees[iii] + nFees[iii-1] + nBest[iii-3]}); //or play this match and the last one too | |
std::cout << nBest[N-1]; | |
return 0; | |
} |
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
//ZCO 2014 Session 2 Problem 1 | |
//Problem Statement: http://www.iarcs.org.in/inoi/2014/zco2014/zco2014-2a.php | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
typedef std::vector <long long unsigned> vll; | |
int main(){ | |
int N; | |
std::cin >> N; | |
vll nBudgets; | |
for (long long unsigned nTemp,iii=0; iii < N; iii++){ | |
std::cin >> nTemp; | |
nBudgets.push_back(nTemp); | |
} | |
std::sort(nBudgets.begin(),nBudgets.end()); | |
long long unsigned nProfit = 0; | |
for (int nPotentialProfit,iii=0; iii < N; iii++) | |
{ | |
nPotentialProfit = nBudgets[iii]*(nBudgets.size()-iii); | |
nProfit = (nProfit > nPotentialProfit) ? nProfit : nPotentialProfit; | |
} | |
std::cout << nProfit; | |
return 0; | |
} |
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
//ZCO 2013 Session 1 Problem 1 | |
//Problem Statement: http://www.iarcs.org.in/inoi/2014/zco2014/zco2014-1a.php | |
#include <iostream> | |
int main(){ | |
int N, H; | |
std::cin >> N >> H; | |
int *nStacks = new int[N]; | |
for (int iii=0; iii < N; iii++) | |
std::cin >> nStacks[iii]; | |
int nCommand = -1; | |
int nCranePos = 0; | |
bool isCraneFull = false; | |
while (nCommand){ | |
std::cin >> nCommand; | |
switch(nCommand) | |
{ | |
case 1: | |
if (nCranePos > 0) | |
nCranePos--; | |
break; | |
case 2: | |
if (nCranePos < N-1) | |
nCranePos++; | |
break; | |
case 3: | |
if (!isCraneFull && nStacks[nCranePos] > 0) | |
{ | |
isCraneFull = true; | |
nStacks[nCranePos]--; | |
} | |
break; | |
case 4: | |
if (isCraneFull && nStacks[nCranePos] < H) | |
{ | |
isCraneFull = false; | |
nStacks[nCranePos]++; | |
} | |
break; | |
case 0: | |
break; | |
} | |
} | |
for(int iii = 0; iii < N; iii++) | |
std::cout << nStacks[iii] << " "; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment