Advertisement
a53

dreptc

a53
Sep 10th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, c;
  6. int cnt;
  7.  
  8. vector< pair<int,int> > v[2005];
  9.  
  10. void Read()
  11. {
  12. int i, x, y, k;
  13. ifstream fin("dreptc.in");
  14.  
  15. fin >> n;
  16. fin >> c;
  17.  
  18. for(i = 1; i <= n; i++)
  19. {
  20. fin >> x >> y >> k;
  21. x += 1000;
  22. y += 1000;
  23. v[x].push_back({y, k});
  24. }
  25. fin.close();
  26. }
  27.  
  28. void Contor(int L1, int L2)
  29. {
  30. int i, j, N, M;
  31. int color[6];
  32. for (i = 1; i <= c; i++)
  33. color[i] = 0;
  34. N = v[L1].size();
  35. M = v[L2].size();
  36. i = j = 0;
  37. while (i < N && j < M)
  38. {
  39. if (v[L1][i].first < v[L2][j].first)
  40. i++;
  41. else if (v[L1][i].first > v[L2][j].first)
  42. j++;
  43. else
  44. {
  45. if (v[L1][i].second == v[L2][j].second)
  46. color[v[L1][i].second]++;
  47. i++; j++;
  48. }
  49. }
  50. for (i = 1; i <= c; i++)
  51. if (color[i] > 1)
  52. cnt += (color[i]*(color[i]-1)/2);
  53. }
  54.  
  55. void Rezolvare()
  56. {
  57. int i, L1, L2;
  58. for (i = 0; i <= 2000; i++)
  59. if (v[i].size() > 0)
  60. sort(v[i].begin(), v[i].end());
  61. cnt = 0;
  62. for (L1 = 0; L1 < 2000; L1++)
  63. if (v[L1].size() > 0)
  64. for (L2 = L1 + 1; L2 <= 2000; L2++)
  65. if (v[L2].size() > 0)
  66. Contor(L1, L2);
  67. ofstream fout("dreptc.out");
  68. fout << cnt << "\n";
  69. fout.close();
  70. }
  71.  
  72. int main()
  73. {
  74. Read();
  75. Rezolvare();
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement