Gym - 102267F F - Arena Olympics 判断点是否在视野+拓扑排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gym - 102267F F - Arena Olympics 判断点是否在视野+拓扑排序相关的知识,希望对你有一定的参考价值。


Kassandra is participating in the Arena Olympics of Sparta. In order to win the arena fight, she has to knockout all the other NN fighters.

Being a computer scientist, she wanted to do it while preserving her energy as much as possible, so she wants to win the fight without being noticed by any of the other fighters. To be more exact, she knows the position of each other fighter in the arena, the angle of the center of his field of view, and the range of his field of view.

If she knocks a fighter out while shes in the field of view of another fighter, she will be noticed and she would have to fight everyone face on. So she wonders if there exists an order of fighters to knockout such that no one notices her during the whole process.

Print any permutation such that if she knocks-out the fighters in this order, she wont be noticed. Or print −1−1 if there exists no such permutation.

Note that Kassandra can move freely while not knocking someone out to get to the position of any other fighter.

Input

The first line of the input will contain an integer NN (1≤N≤3000)(1≤N≤3000).

Each of the following lines will contain 4 integers each: xixi, yiyi, aiai, riri (−106≤xi,yi≤106,0≤ai≤359,0≤ri≤89)(−106≤xi,yi≤106,0≤ai≤359,0≤ri≤89) - the xx coordinate, yy coordinate, the angle of the center of the field of view, and the range of the field of view of the ithith fighter respectively. No two fighters share the same position.

Output

If there exists such a permutation, print the order of the ids of the NNparticipants on a single line separated by a space. Otherwise, print −1−1.

Examples

Input

4
-2 1 35 25
-3 -2 35 25
0 -3 110 25
2 1 245 25

Output

2 4 3 1

Input

2
-3 -3 45 45
3 3 225 45

Output

-1

Note

The field of view ranges from the angle a−ra−r to the angle a+ra+r.

Below is the illustration of the first case:

Gym

 

题意:

n个横纵坐标点,每一个点都有a-r和a+r(但为角度,与x的正半轴)的视角,注意视角范围不大于180。现在你要消灭人,但你消灭的时候不允许叫别人看到输出任意消灭顺序。

分析:

如何判断一个人手否能被别人看到,我们定义l[i]和r[i]为其角度范围

Gym

需要判断角度角1角度是否在蓝色的角度里l[i]与r[i]中,但有一种特殊情况

Gym

我们发现l[i]是大于r[i]的,这个情况需要注意,只需要角1<=r[i]或者>=l[i]

剩下的跑拓扑就ok

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3000 + 10;
const double eps = 1e-9;
const double PI = acos(-1);
int n,x[N],y[N],l[N],r[N],in[N];
int G[N][N];
vector<int>ans;
queue<int>q;
int main()

int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)

int a,rn;
scanf("%d%d%d%d",&x[i],&y[i],&a,&rn);
l[i]=(a-rn+360)%360;
r[i]=(a+rn)%360;



for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)

if(i==j)
continue;
int dx=x[j]-x[i];
int dy=y[j]-y[i];
double ang=atan2(dy,dx);

if(ang<0)
ang+=2*PI;

ang*=180/PI;

if(l[i]>r[i])

if(ang-eps<=r[i]||ang+eps>=l[i])

G[i][j]=1;
in[j]++;


else

if(ang+eps>=l[i]&&ang-eps<=r[i])

G[i][j]=1;
in[j]++;






for(int i=1; i<=n; i++)

if(in[i]==0)
q.push(i);



while(!q.empty())

int u=q.front();
q.pop();
ans.push_back(u);

for(int i=1; i<=n; i++)

if(G[u][i]==1&&in[i]>0)

in[i]--;
if(in[i]==0)
q.push(i);



if(ans.size()<n)

printf("-1\\n");

else

for(int i=0; i<n-1; i++)

printf("%d ",ans[i]);

printf("%d\\n",ans[n-1]);



return 0;

 

以上是关于Gym - 102267F F - Arena Olympics 判断点是否在视野+拓扑排序的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena(组合数,DP )

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena(组合数,DP )

2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys

GYM 101128 F.Landscaping(网络流)

F - Fabricating Sculptures Gym - 102428F (dp + 前缀和维护)

Gym-100676F Palindrome