Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <cstdio>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <map>
  5. #include <set>
  6. #include <cmath>
  7. #include <iostream>
  8. #include <ctime>
  9. #include <utility>
  10. #include <string>
  11. #include <memory.h>
  12. using namespace std;
  13.  
  14. #define forn( i,n ) for ( int i=0; i<(int)(n); i++ )
  15. #define sz(a) (int)((a).size())
  16. #define pb push_back
  17. #define mp make_pair
  18. typedef long long ll;
  19. typedef double ld;
  20. typedef pair<int,int> pii;
  21.  
  22. const int maxn = 100005;
  23. const ld pi = acos(-1.0);
  24. const ld eps = 1e-8;
  25. const ld ang = 0.732423543;
  26. const ld co = cos(ang);
  27. const ld si = sin(ang);
  28.  
  29. struct point
  30. {
  31.   ld x, y;
  32.   int id;
  33. };
  34.  
  35.  
  36. bool operator<(const point& a, const point& b)
  37. {
  38.   if (fabs(a.x-b.x) > eps) return a.x < b.x;
  39.   if (fabs(a.y-b.y) > eps) return a.y < b.y;
  40.   return a.id < b.id;
  41. }
  42.  
  43. ld dist(const point& a, const point& b)
  44. {
  45.   return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
  46. }
  47.  
  48.  
  49. point a[maxn];
  50. int b[maxn];
  51. vector<int> ans[maxn];
  52. int n;
  53.  
  54. int main()
  55. {
  56.   freopen( "a.in", "r", stdin );
  57.   freopen( "a.out", "w", stdout );
  58.  
  59.  
  60.   scanf("%d", &n);
  61.   forn (i, n)
  62.   {
  63.     int x, y; scanf("%d %d", &x, &y);
  64.     a[i].x = co*x + si*y;
  65.     a[i].y = -si*x + co*y;
  66.   }
  67.  
  68.   sort(a, a+n);
  69.   forn (i, n)
  70.   {
  71.     ld d = 1e15;
  72.     int q = -1;
  73.    
  74.     for (int j=i-1; j>=0; --j)
  75.     {
  76.       if (a[i].x > a[j].x + d) break;
  77.       ld dd = dist(a[i], a[j]);
  78.       if (d > dd) d = dd, q = a[j].id;
  79.     }
  80.     for (int j=i+1; j<n; ++j)
  81.     {
  82.       if (a[j].x > a[i].x + d) break;
  83.       ld dd = dist(a[i], a[j]);
  84.       if (d > dd) d = dd, q = a[j].id;
  85.     }
  86.    
  87.     b[i] = q;    
  88.   }
  89.   forn (i, n) ans[b[i]].pb(i);
  90.   forn (i, n)
  91.   {
  92.     printf("%d:", i+1);
  93.     forn (j, sz(ans[i])) printf(" %d", ans[i][j]+1);
  94.     puts("");
  95.   }
  96.  
  97.  
  98.  
  99.  
  100.   return 0;
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. #include <cstdio>
  177. #include <vector>
  178. #include <algorithm>
  179. #include <map>
  180. #include <set>
  181. #include <cmath>
  182. #include <iostream>
  183. #include <ctime>
  184. #include <utility>
  185. #include <string>
  186. #include <memory.h>
  187. using namespace std;
  188.  
  189. #define forn( i,n ) for ( int i=0; i<(int)(n); i++ )
  190. #define sz(a) (int)((a).size())
  191. #define pb push_back
  192. #define mp make_pair
  193. typedef long long ll;
  194. typedef double ld;
  195. typedef pair<int,int> pii;
  196.  
  197. const int maxn = 100005;
  198. const ld pi = acos(-1.0);
  199. const ld eps = 1e-8;
  200. const ld ang = 0.732423543;
  201. const ld co = cos(ang);
  202. const ld si = sin(ang);
  203.  
  204. struct point
  205. {
  206.   ld x, y;
  207.   int id;
  208. };
  209.  
  210.  
  211. bool operator<(const point& a, const point& b)
  212. {
  213.   if (fabs(a.x-b.x) > eps) return a.x < b.x;
  214.   if (fabs(a.y-b.y) > eps) return a.y < b.y;
  215.   return a.id < b.id;
  216. }
  217.  
  218. ld dist(const point& a, const point& b)
  219. {
  220.   return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
  221. }
  222.  
  223.  
  224. point a[maxn];
  225. int b[maxn];
  226. vector<int> ans[maxn];
  227. int n;
  228.  
  229. int main()
  230. {
  231.   freopen( "a.in", "r", stdin );
  232.   freopen( "a.out", "w", stdout );
  233.  
  234.  
  235.   scanf("%d", &n);
  236.   forn (i, n)
  237.   {
  238.     int x, y; scanf("%d %d", &x, &y);
  239.     a[i].x = co*x + si*y;
  240.     a[i].y = -si*x + co*y;
  241.   }
  242.  
  243.   sort(a, a+n);
  244.   forn (i, n)
  245.   {
  246.     ld d = 1e15;
  247.     int q = -1;
  248.    
  249.     for (int j=i-1; j>=0; --j)
  250.     {
  251.       if (a[i].x > a[j].x + d) break;
  252.       ld dd = dist(a[i], a[j]);
  253.       if (d > dd) d = dd, q = a[j].id;
  254.     }
  255.     for (int j=i+1; j<n; ++j)
  256.     {
  257.       if (a[j].x > a[i].x + d) break;
  258.       ld dd = dist(a[i], a[j]);
  259.       if (d > dd) d = dd, q = a[j].id;
  260.     }
  261.    
  262.     b[i] = q;    
  263.   }
  264.   forn (i, n) ans[b[i]].pb(i);
  265.   forn (i, n)
  266.   {
  267.     printf("%d:", i+1);
  268.     forn (j, sz(ans[i])) printf(" %d", ans[i][j]+1);
  269.     puts("");
  270.   }
  271.  
  272.  
  273.  
  274.  
  275.   return 0;
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement