清泉逐流

做着努力,等待幸福到来
» 我的笔记

使用sort对二维数组排序

时间 : 2014-09-30 19:49 分类 : C/C++

#include <iostream> #include <algorithm> using namespace std; struct OP { inline bool operator()( int* e1, int* e2) { if( e1[0] == e2[0] ){ if( e1[1] = e2[1] ){ return e1[2]<e2[2]; } return e1[1]<e2[1]; } return e1[0]<e2[0]; } }op; int main(int argc, char **argv) { int arr[3][3] = {1,2,3, 4,0,1, 2,3,1}; // warning : use dynamic pointer to sort int *arr1[3]; for (int i=0;i<3;i++){

查看全文 »

二维vector的使用和排序

时间 : 2014-09-30 19:48 分类 : C/C++

#include <vector> #include <algorithm> #include <iostream> using namespace std; // Binary function that accepts two elements in the range as arguments, // and returns a value convertible to bool. The value returned indicates // whether the element passed as first argument is considered to go // before the second in the specific strict weak ordering it defines. // The function shall not modify any of its arguments. // This can either be a function pointer or a function object. struct SORT{ inline bool operator

查看全文 »

Binary tree

时间 : 2014-09-10 20:13 分类 : C/C++

#include <iostream> #include <fstream> #include <vector> using namespace std; template <typename T> struct BNode{ BNode *l; BNode *r; T data; }; template <typename T> class BTree{ public: static const int PRE_ORDER = 1; static const int POST_ORDER = 2; static const int IN_ORDER = 3; BTree(); ~BTree(); void SetEmptyValue(T value){ m_empty_value = value; } void Create(vector<T> &seq, const int order

查看全文 »

Binary search tree

时间 : 2014-09-10 20:12 分类 : C/C++

#include <iostream> #include <fstream> #include <deque> using namespace std; template <typename T> struct BNode{ BNode *l; BNode *r; T data; }; template <typename T> class BSTree{ public: static const int PRE_ORDER = 1; static const int POST_ORDER = 1; static const int IN_ORDER = 1; BSTree(); ~BSTree(); bool Insert(T data); bool Delete(T data); BNode<T> *Find(T data); void Dest

查看全文 »

Map usage

时间 : 2014-09-09 20:13 分类 : C/C++

map<char, int> map_test; for(int i=0; i<10; i++){ char key = rand() % 26 + 'A'; int value = rand() % 100; map_test[key] = value; } // find delete map<char, int>::interacot it; it = map_test.find('B'); if( map_test.end() != it ){ // Found } // Delete map_test.delete(<interactor>); // Interactor for(map<char, int>::iterator it=map_test.begin(); it!=map_test.end(); it++){ // Key it->first; // Value it->second; } // Sort // Map sorted by key automatically, you cann't s

查看全文 »

Sort Code

时间 : 2014-09-09 20:12 分类 : C/C++

void quick_sort(int *arr, int left, int right) { assert(NULL != arr); if( left < right ){ int i = left, j = right; int x = arr[i]; while( i < j ){ while( i < j && arr[j] > x ){ j --; } if( i < j ){ arr[i] = arr[j]; i ++; } while( i < j && arr[i] < x ){ i ++ ; } if( i < j ){

查看全文 »

Poj1008

时间 : 2014-09-09 20:11 分类 : C/C++

#include <string> #include <iostream> #include <map> using namespace std; #define HAAB_YEAR_DAYS (20*18+1*5) #define TZO_YEAR_DAYS (13*20) struct Haab_date{ int day; int year; }; struct Tzolkin_date{ string day_str; int year; }; void convert(Haab_date &haab, Tzolkin_date &tzo) { static string tzo_map[20]; tzo_map[0] = "imix"; tzo_map[1] = "ik"; tzo_map[2] = "akbal"; tzo_map[3] = "kan"; tzo_map[4] = "chicchan"; tzo_map[5] = "cimi"; tzo_map[6] =

查看全文 »

Poj1007

时间 : 2014-09-09 20:11 分类 : C/C++

#include <iostream> #include <string> #include <cstdlib> using namespace std; struct DNA{ string s; int value; }; int cmp(const DNA *a, const DNA *b) { return a->value - b->value; } int main(int argc, char* argv[]) { int length, count; cin >> length >> count; DNA *it = new DNA[count]; for(int i =0; i!=count; i++){ cin >> it[i].s; for(int j=0; j!=length; j++){ for(int k=j+1; k!=length; k++){

查看全文 »

Poj1006

时间 : 2014-09-09 20:11 分类 : C/C++

#include <iostream> #define MAX_EX_DATE 21252 #define PERIOD_P 23 #define PERIOD_E 28 #define PERIOD_I 33 using namespace std; int main(int argc, char* argv[]) { int p,e,i,d; int case_cnt = 1; while(true) { int ans; cin >> p >> e >> i >> d; if( -4 == p+i+e+d ){

eak; } if(p>=PERIOD_P){ p = p - p/PERIOD_P*PERIOD_P; } if(e>

查看全文 »

Poj1005

时间 : 2014-09-09 20:10 分类 : C/C++

#include <iostream> #define _USE_MATH_DEFINES #include <cmath> using namespace std; int main(int argc, char* argv[]) { int count; cin >> count; for(int cnt=0; cnt<count; cnt++){ double x,y,s; cin >> x >> y; s = M_PI * (x*x + y*y); int year = 1; for(;;year++){ if( year*100.0F > s ){

eak; } } cout <

查看全文 »
» 笔记大类