Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <climits>
  4. #include <cmath>
  5. #include <string>
  6. #include <sstream>
  7. #include <vector>
  8. #include <map>
  9. #include <set>
  10. #include <vector>
  11.  
  12. using namespace std;
  13.  
  14. double vectorDistance(vector<double>::iterator first, vector<double>::iterator last, vector<double>::iterator first2) {
  15. double ret = 0.0;
  16. while (first != last) {
  17. double dist = (*first++) - (*first2++);
  18. ret += dist * dist;
  19. }
  20. return ret > 0.0 ? sqrt(ret) : 0.0;
  21. }
  22.  
  23. int toDecimal(string& s, int b)
  24. {
  25. int n = s.size();
  26. int d = 0;
  27. for(int i = 0; i<n; ++i)
  28. {
  29. int digit = s.c_str()[n-1-i] - '0';
  30. if(s.c_str()[n-1-i] >= 'a' && s.c_str()[n-1-i] <= 'z')
  31. {
  32. digit = s.c_str()[n-1-i] - 'a' + 10;
  33. }
  34. d += digit * pow(b,i);
  35. }
  36. return d;
  37. }
  38.  
  39. vector<string> split(const string &s, char delim) {
  40. stringstream ss(s);
  41. vector<string> elems;
  42. string item;
  43. while (getline(ss, item, delim)) {
  44. elems.push_back(item);
  45. }
  46. return elems;
  47. }
  48.  
  49. int occurences(const string& s, char needle){
  50. return count(s.begin(), s.end(), '-');
  51. }
  52.  
  53. void paint( vector<vector<int>>& mat, int x, int y, int c, int f)
  54. {
  55. if(x < 0 || y < 0 || x >= mat.size() || y>= mat[x].size())
  56. {
  57. return;
  58. }
  59. if(mat[x][y] != f)
  60. {
  61. return;
  62. }
  63. mat[x][y] = c;
  64. paint(mat,x+1,y,c,f);
  65. paint(mat,x+1,y,c,f);
  66. paint(mat,x,y+1,c,f);
  67. paint(mat,x,y-1,c,f);
  68.  
  69. paint(mat,x+1,y+1,c,f);
  70. paint(mat,x+1,y-1,c,f);
  71. paint(mat,x-1,y+1,c,f);
  72. paint(mat,x-1,y+1,c,f);
  73. }
  74.  
  75. template <typename T>
  76. void print_v(vector<T> v)
  77. {
  78. for(auto& i : v)
  79. {
  80. cout << i << " ";
  81. }
  82. cout << endl;
  83. }
  84.  
  85.  
  86.  
  87. template <typename T>
  88. void print_mat(const vector<vector<T>>& mat)
  89. {
  90. for(auto& i : mat)
  91. {
  92. print_v(i);
  93. }
  94. }
  95. template<typename T>
  96. map<T,int> getFreqs(const vector<T>& vs)
  97. {
  98. map<T,int> freqs;
  99. for(const auto& v : vs)
  100. {
  101. if(freqs.find(v) == freqs.end())
  102. {
  103. freqs[v] = 1;
  104. }
  105. else
  106. {
  107. freqs[v]++;
  108. }
  109. }
  110. return freqs;
  111. }
  112.  
  113. template<typename T>
  114. void print_freqs(const map<T,int>& f)
  115. {
  116. for(auto p : f)
  117. {
  118. cout << p.first << " " << p.second << endl;
  119. }
  120. }
  121.  
  122.  
  123. template<typename T>
  124. int countPathsDFS(map<T,vector<T>> & ds, const T& from, const T& to, const T& nil)
  125. {
  126. if(from == to)
  127. {
  128. return 1;
  129. }
  130.  
  131. int count = 0;
  132.  
  133. for(T& d : ds[from])
  134. {
  135. if(d == nil) continue;
  136.  
  137. T tmp = d;
  138.  
  139. d = nil;
  140. count += countPaths(ds,tmp,to,nil);
  141. d = tmp;
  142. }
  143.  
  144. return count;
  145. }
  146.  
  147.  
  148.  
  149.  
  150. int main()
  151. {
  152. return 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement