Created
October 24, 2010 00:17
-
-
Save ybenjo/642876 to your computer and use it in GitHub Desktop.
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 <unordered_map> | |
#include <map> | |
#include <iostream> | |
using namespace std; | |
struct myeq : std::binary_function<pair<int , int> , pair<int , int> , bool>{ | |
bool operator() (const pair<int , int> & x , const pair<int , int> & y) const{ | |
//keyの一致って普通これですよね | |
return x.first == y.first && x.second == y.second; | |
} | |
}; | |
struct myhash : std::unary_function<pair<int , int> , size_t>{ | |
private: | |
const hash<int> h_int; | |
public: | |
myhash() : h_int() {} | |
size_t operator()(const pair<int , int> & p) const{ | |
//http://stackoverflow.com/questions/738054/hash-function-for-a-pair-of-long-long | |
size_t seed = h_int(p.first); | |
return h_int(p.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); | |
} | |
}; | |
int main(){ | |
int sum = 0; | |
//一つめの数字が何してるのかわかってない | |
myhash h; | |
myeq e; | |
//unordered_map<pair<int , int> , int , myhash , myeq> m(3 , h , e); | |
unordered_map<pair<int , int> , int , myhash , myeq> m(3); | |
for(int i = 0; i < 1000; ++i){ | |
for(int j = 0; j < 1000; ++j){ | |
//m.insert(pair<pair<int,int> , int>(make_pair(i, j) , 1)); | |
m[make_pair(i, j)] = 1; | |
} | |
} | |
for(int i = 0; i < 1000; ++i){ | |
for(int j = 0; j < 1000; ++j){ | |
sum += m[make_pair(i, j)]; | |
} | |
} | |
cout << sum << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment