Skip to content

Instantly share code, notes, and snippets.

@Gabrielgtt
Created June 24, 2018 18:37
Show Gist options
  • Select an option

  • Save Gabrielgtt/818e943db8fdfdbf2eb2215e6afef82e to your computer and use it in GitHub Desktop.

Select an option

Save Gabrielgtt/818e943db8fdfdbf2eb2215e6afef82e to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define ii pair <int, int>
#define f first
#define s second
#define INF 1e9
#define MOD 1000000007
#define pb push_back
#define MAXN 100010
#define MAXCOR 102
#define debug(x) cerr << #x << " = " << x << endl
#define debug_arr(x, tam) cerr << #x << " = "; for (int i=0;i<tam;i++) printf("%d%c", x[i], " \n"[i == tam-1])
using namespace std;
struct vetor{
ll x, y, index;
} vetores[MAXN];
int ans[MAXN];
int dir(vetor a){
if (a.x > 0 && a.y > 0) return 1;
if (a.x < 0 && a.y > 0) return 2;
if (a.x < 0 && a.y < 0) return 3;
if (a.x > 0 && a.y < 0) return 4;
}
vector <vetor> prim;
vector <vetor> sec;
bool comp(vetor a, vetor b){
double dist1 = sqrt((double)((a.x*a.x) + (a.y*a.y)));
double dist2 = sqrt((double)((b.x*b.x) + (b.y*b.y)));
return dist1 <= dist2;
}
int main(){
int n;
scanf("%d", &n);
for (int i=0; i<n; i++){
scanf("%lld %lld", &vetores[i].x, &vetores[i].y);
vetores[i].index = i;
if (dir(vetores[i]) & 1){
sec.emplace_back(vetores[i]);
} else {
prim.emplace_back(vetores[i]);
}
}
sort(prim.begin(), prim.end(), comp);
sort(sec.begin(), sec.end(), comp);
vetor res;
res.x = 0;
res.y = 0;
vetor aux;
aux.x = 0;
aux.y = 0;
for (int i=0; i<prim.size(); i++){
if (dir(aux) == dir(prim[i])){
ans[prim[i].index] = -1;
aux.y -= prim[i].y;
aux.x -= prim[i].x;
} else {
ans[prim[i].index] = 1;
aux.x += prim[i].x;
aux.y += prim[i].y;
}
// printf("%lld %lld\n", res.x, res.y);
}
res.x += aux.x;
res.y += aux.y;
aux.x = 0;
aux.y = 0;
for (int i=0; i<sec.size(); i++){
if (dir(aux) == dir(sec[i])){
ans[sec[i].index] = -1;
aux.x -= sec[i].x;
aux.y -= sec[i].y;
} else {
ans[sec[i].index] = 1;
aux.y += sec[i].y;
aux.x += sec[i].x;
}
}
res.x += aux.x;
res.y += aux.y;
for (int i=0; i<n; i++){
printf("%d%c", ans[i], " \n"[i == n-1]);
}
// printf("%lld %lld\n", res.x, res.y);
// cout << sqrt((res.x * res.x) + (res.y * res.y)) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment