Advertisement
double_trouble

поджигатель

Dec 24th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <string>
  6. #include <algorithm>
  7. #include <string>
  8. #include <string.h>
  9.  
  10. #define F first
  11. #define S second
  12.  
  13.  
  14.  
  15. using namespace std;
  16.  
  17. vector <pair <int, int> > a;
  18. double g[100][100], f[100][100];
  19. bool p[100];
  20.  
  21.  
  22. int vg(long x, long y)
  23. {
  24.     bool f = true;
  25.     //int r;
  26.     for (int j = 0; j < a.size(); j++)
  27.         {
  28.             //cout << x << " " << y << "*" << a[j].F << " " << a[j].S << endl;
  29.             if (a[j].F == x && a[j].S == y)
  30.             {
  31.                 //cout <<a[j].F << " " << x << " " << a[j].S << " " << y << " oi vse" << endl;
  32.                 return j;
  33.             }
  34.             /*if (a[j].F == x)
  35.                 if (a[j].S == y)
  36.                 {
  37.  
  38.                     cout << "&" ;
  39.                     r = j;
  40.                 }*/
  41.         }
  42.     //if (f)
  43.     //{
  44.         a.push_back(make_pair(x, y));
  45.         return a.size() - 1;
  46.     //}
  47.     //cout << r << "%" << endl;
  48.     //return r;
  49. }
  50.  
  51. int main()
  52. {
  53.     ios_base::sync_with_stdio(0);
  54.     cin.tie(0);
  55.     cout.tie(0);
  56.     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  57.     int n;
  58.     cin >> n;
  59.     //for (int i = 0; i < n*2; i++)
  60.     //    for (int j= 0; j < n*2; j++)
  61.     //    g[i][j] = 0;
  62.     int k = 0;
  63.     int l, m;
  64.     //a.push_back(make_pair(0, 0));
  65.     int x1, y1, x3, y3, x2, y2;
  66.     double t;
  67.     /*cin >> x1 >> y1 >> x3 >> y3 >> t;
  68.     x1 *= 2; y1 *= 2; x3 *= 2; y3 *= 2; t /= 2;
  69.     x2 = (x1 + x3) / 2; y2 = (y1 + y3) / 2;
  70.     k = vg(x1, y1);
  71.     l = vg(x2, y2);
  72.     m = vg(x3, y3);
  73.     //p[k] = true; p[m] = true;
  74.     g[k][l] = t; g[l][k] = t;
  75.     g[l][m] = t; g[m][l] = t;
  76.     //k = m;
  77.     */
  78.     for (int i = 0; i < n; i++)
  79.     {
  80.  
  81.         cin >> x1 >> y1 >> x3 >> y3 >> t;
  82.         x1 *= 2; y1 *= 2; x3 *= 2; y3 *= 2; t /= 2;
  83.         x2 = (x1 + x3) / 2; y2 = (y1 + y3) / 2;
  84.         //if (vg(x1, y1) == a.size() - 1)
  85.         //    a.push_back(make_pair(x1, y2));
  86.         k = vg(x1, y1);
  87.         l = vg(x2, y2);
  88.         m = vg(x3, y3);
  89.         //p[i] = true;
  90.         //p[k] = true; p[m] = true;
  91.         g[k][l] = t; g[l][k] = t;// f[l][k] = t; f[k][l] = t;
  92.         g[l][m] = t; g[m][l] = t;// f[m][l] = t; f[l][m] = t;
  93.         //k = m;
  94.     }
  95.     //cout << x1 << " " << y1 << " " << x3 << " " <<y3 << endl;
  96.     n = a.size();
  97.     //cout << n << endl;
  98.     /*for (int i = 0; i < n; i++)
  99.         cout << a[i].F << " " << a[i].S << endl;
  100.         cout << endl;
  101.     */
  102.     for (int i= 0; i < n; i++)
  103.     {
  104.         for (int j= 0; j < n; j++)
  105.             cout << g[i][j] << " ";
  106.         cout << endl;
  107.     }
  108.     cout << endl;
  109.     for (int u = 0; u < n; u++)
  110.         for (int i= 0; i < n; i++)
  111.         for (int j= 0; j < n; j++)
  112.         {
  113.             //cout << g[i][j] << " " << g[i][u] << " " << g[u][j] << " ";
  114.             if (g[i][u] && g[u][j])
  115.             if (g[i][j] > g[i][u] + g[u][j]  || (g[i][j] == 0 && i != j) )
  116.                 g[i][j] = g[i][u] + g[u][j];
  117.             //cout << g[i][j] << endl;
  118.         }
  119.     for (int i= 0; i < n; i++)
  120.     {
  121.         for (int j= 0; j < n; j++)
  122.             cout << g[i][j] << " ";
  123.         cout << endl;
  124.     }
  125.     cout << endl;
  126.  
  127.     double ans = 10000000000000;
  128.     int ans1, ans2, ans11, ans22;
  129.     for (int i= 0; i < n; i++)
  130.     {
  131.         //if (!p[i])
  132.         //    continue;
  133.         if (a[i].F % 2 == 0 && a[i].S % 2 == 0)
  134.         {
  135.             double mxm = -1000;
  136.             for (int j = 0; j < n; j++)
  137.         {
  138.  
  139.             //cout << g[i][j] << endl;
  140.             if (g[i][j] > mxm)
  141.             {
  142.                 mxm = g[i][j];
  143.                 ans1 = a[i].F / 2;
  144.                 ans2 = a[i].S / 2;
  145.             }
  146.             cout << mxm << " " << ans1 << " " << ans2 << " " << a[j].F << " " << a[j].S << endl;
  147.         }
  148.         //cout << mxm << " " << ans1 << " " << ans2 << endl;
  149.        if (mxm >= 0 && mxm < ans)
  150.         {
  151.             ans = mxm;
  152.             ans11 = ans1;
  153.             ans22 = ans2;
  154.         }
  155.         }
  156.        //ans = min(ans, mxm);
  157.     }
  158.     cout << ans11 << " " << ans22 << endl;
  159.     printf("%.2f", ans);
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement