Last active
December 13, 2015 16:59
-
-
Save tsu-nera/4944781 to your computer and use it in GitHub Desktop.
TopCoder SRM570 Dev2 Level1
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
/* TopCoder | |
* SRM : 570 | |
* Division : 1 | |
* Level : 2 | |
* | |
* Created on: 2013/02/13 | |
* Author: tsu_nera<[email protected]> | |
*/ | |
#include <algorithm> | |
#include <iostream> | |
#include <map> | |
#include <numeric> | |
#include <set> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
class Chopsticks { | |
public: int getmax(vector<int> length) { | |
int count = 0; | |
int i; | |
int num_count[101]; | |
if( sizeof(length) == 1 ) return 0; | |
for(i=0; i < 101; i++ ) { | |
num_count[i] = 0; | |
} | |
for(int j=0; j < (int)length.size(); j++) { | |
num_count[length[j]]++; | |
} | |
for(i=0; i<100; i++) { | |
if( num_count[i] == 0 ) | |
continue; | |
if( num_count[i] > 1 ) { | |
count++; | |
num_count[i] -=2; | |
i--; | |
} | |
} | |
return count; | |
} | |
}; |
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
/* TopCoder | |
* SRM : 570 | |
* Division : 1 | |
* Level : 2 | |
* | |
* Created on: 2013/02/14 | |
* Author: tsu_nera<[email protected]> | |
*/ | |
#include <algorithm> | |
#include <iostream> | |
#include <map> | |
#include <numeric> | |
#include <set> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++) | |
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) | |
#define ISEQ(c) (c).begin(), (c).end() | |
class Chopsticks { | |
public: int getmax(vector<int> length) { | |
map<int, int> dic; | |
for (int i = 0; i < (int)length.size(); i++) { | |
dic[length[i]] = 0; | |
} | |
for (int i = 0; i < (int)length.size(); i++) { | |
dic[length[i]]++; | |
} | |
int ans = 0; | |
map<int, int>::iterator it; | |
for (it = dic.begin() ; it != dic.end(); it++) { | |
ans += ( (*it).second /2); | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment