Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <algorithm>
  6. #include <string>
  7. #include<vector>
  8. #include <istream>
  9. #include<iomanip>
  10. #include<stack>
  11. using namespace std;
  12.  
  13. struct item {
  14. int tid;
  15. int x;
  16. int y;
  17.  
  18. item(){}
  19.  
  20. item(int _tid, int _x, int _y) {
  21. tid = _tid;
  22. x = _x;
  23. y = _y;
  24. }
  25.  
  26. void scan() {
  27. cin >> tid >> x >> y;
  28. }
  29. };
  30.  
  31. double lenght(double x, double y, double x1, double y1) {
  32. return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
  33. }
  34.  
  35. bool cmp(item a, item b) {
  36. return a.x < b.x || a.x == b.x && a.y < b.y;
  37. }
  38.  
  39.  
  40. int main(){
  41. #ifdef _DEBUG
  42. freopen("input.txt", "r", stdin);
  43. freopen("output.txt", "w", stdout);
  44. #endif // _DEBUG
  45. int n, m;
  46. cin >> n >> m;
  47. vector<item> A(n), B(m);
  48. for (int i = 0; i < n; i++) {
  49. A[i].scan();
  50. }
  51. sort(A.begin(), A.end(), cmp);
  52. for (int i = 0; i < m; i++) {
  53. B[i].scan();
  54. }
  55. double ans = 1e9;
  56. int x = 0, y = 0;
  57. for (int i = 0; i < m; i++) {
  58. double cnt = 0;
  59. for (int j = 0; j < n; j++) {
  60. double l = lenght(A[j].x, A[j].y, B[i].x, B[i].y);
  61. if (A[j].tid != B[i].tid)
  62. l = l * 2;
  63. cnt += l;
  64. }
  65. if (ans > cnt) {
  66. ans = cnt;
  67. x = B[i].x;
  68. y = B[i].y;
  69. }
  70. }
  71. cout << x << " " << y;
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement