Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <cmath>
- #include <iostream>
- #include <ctime>
- #include <utility>
- #include <string>
- #include <memory.h>
- using namespace std;
- #define forn( i,n ) for ( int i=0; i<(int)(n); i++ )
- #define sz(a) (int)((a).size())
- #define pb push_back
- #define mp make_pair
- typedef long long ll;
- typedef double ld;
- typedef pair<int,int> pii;
- const int maxn = 100005;
- const ld pi = acos(-1.0);
- const ld eps = 1e-8;
- const ld ang = 0.732423543;
- const ld co = cos(ang);
- const ld si = sin(ang);
- struct point
- {
- ld x, y;
- int id;
- };
- bool operator<(const point& a, const point& b)
- {
- if (fabs(a.x-b.x) > eps) return a.x < b.x;
- if (fabs(a.y-b.y) > eps) return a.y < b.y;
- return a.id < b.id;
- }
- ld dist(const point& a, const point& b)
- {
- return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
- }
- point a[maxn];
- int b[maxn];
- vector<int> ans[maxn];
- int n;
- int main()
- {
- freopen( "a.in", "r", stdin );
- freopen( "a.out", "w", stdout );
- scanf("%d", &n);
- forn (i, n)
- {
- int x, y; scanf("%d %d", &x, &y);
- a[i].x = co*x + si*y;
- a[i].y = -si*x + co*y;
- }
- sort(a, a+n);
- forn (i, n)
- {
- ld d = 1e15;
- int q = -1;
- for (int j=i-1; j>=0; --j)
- {
- if (a[i].x > a[j].x + d) break;
- ld dd = dist(a[i], a[j]);
- if (d > dd) d = dd, q = a[j].id;
- }
- for (int j=i+1; j<n; ++j)
- {
- if (a[j].x > a[i].x + d) break;
- ld dd = dist(a[i], a[j]);
- if (d > dd) d = dd, q = a[j].id;
- }
- b[i] = q;
- }
- forn (i, n) ans[b[i]].pb(i);
- forn (i, n)
- {
- printf("%d:", i+1);
- forn (j, sz(ans[i])) printf(" %d", ans[i][j]+1);
- puts("");
- }
- return 0;
- }
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- #include <map>
- #include <set>
- #include <cmath>
- #include <iostream>
- #include <ctime>
- #include <utility>
- #include <string>
- #include <memory.h>
- using namespace std;
- #define forn( i,n ) for ( int i=0; i<(int)(n); i++ )
- #define sz(a) (int)((a).size())
- #define pb push_back
- #define mp make_pair
- typedef long long ll;
- typedef double ld;
- typedef pair<int,int> pii;
- const int maxn = 100005;
- const ld pi = acos(-1.0);
- const ld eps = 1e-8;
- const ld ang = 0.732423543;
- const ld co = cos(ang);
- const ld si = sin(ang);
- struct point
- {
- ld x, y;
- int id;
- };
- bool operator<(const point& a, const point& b)
- {
- if (fabs(a.x-b.x) > eps) return a.x < b.x;
- if (fabs(a.y-b.y) > eps) return a.y < b.y;
- return a.id < b.id;
- }
- ld dist(const point& a, const point& b)
- {
- return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
- }
- point a[maxn];
- int b[maxn];
- vector<int> ans[maxn];
- int n;
- int main()
- {
- freopen( "a.in", "r", stdin );
- freopen( "a.out", "w", stdout );
- scanf("%d", &n);
- forn (i, n)
- {
- int x, y; scanf("%d %d", &x, &y);
- a[i].x = co*x + si*y;
- a[i].y = -si*x + co*y;
- }
- sort(a, a+n);
- forn (i, n)
- {
- ld d = 1e15;
- int q = -1;
- for (int j=i-1; j>=0; --j)
- {
- if (a[i].x > a[j].x + d) break;
- ld dd = dist(a[i], a[j]);
- if (d > dd) d = dd, q = a[j].id;
- }
- for (int j=i+1; j<n; ++j)
- {
- if (a[j].x > a[i].x + d) break;
- ld dd = dist(a[i], a[j]);
- if (d > dd) d = dd, q = a[j].id;
- }
- b[i] = q;
- }
- forn (i, n) ans[b[i]].pb(i);
- forn (i, n)
- {
- printf("%d:", i+1);
- forn (j, sz(ans[i])) printf(" %d", ans[i][j]+1);
- puts("");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement