SOLUTION
所选点与其余点的连线与已知线段st若有的交点,则被记录,依照靠近起始点st.s排序,若无k个交点输出-1,若有输出_p[k]
CODE
/*SiberianSquirrel*/
/*CuteKiloFish*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <time.h>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define re register
typedef long long ll;
typedef pair<ll, ll> PII;
typedef unsigned long long ull;
const double eps = 1e-7;
const double pi = acos(-1.0);
const int N = 1e6 + 10, M = 1e6 + 5, INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
int sgn(double x) {
if(fabs(x) < eps) return 0;
if(x > 0) return 1;
return -1;
}
struct Point {
double x, y;
Point(){}
Point(double _x, double _y) {
x = _x;
y = _y;
}
void out() {
printf("%.10f %.10f\n", x, y);
}
double operator*(const Point &a) const {
return x * a.x + y * a.y;
}
double operator^(const Point &a) const {
return x * a.y - y * a.x;
}
Point operator-(const Point &a) const {
return Point(x - a.x, y - a.y);
}
Point operator+(const Point &a) const {
return Point(x + a.x, y + a.y);
}
double dis(const Point &a) const {
return sqrt((x - a.x) * (x - a.x) + (y - a.y) * (y - a.y));
}
}p[1010], s, t, _p[1000010];
struct Line {
Point s, e;
Line(){}
Line(Point _s, Point _e) {
s = _s;
e = _e;
}
Line(double a, double b, double c) {
if(sgn(a) == 0) {
s = Point(0, -c / b);
e = Point(1, -c / b);
} else if(sgn(b) == 0) {
s = Point(-c / a, 0);
e = Point(-c / a, 1);
} else {
s = Point(0, -c / b);
e = Point(1, (-c - a) / b);
}
}
void out() {
s.out();
e.out();
}
Point crosspoint(Line v) {
double a1 = (v.e - v.s) ^ (s - v.s);
double a2 = (v.e - v.s) ^ (e - v.s);
return Point((s.x * a2 - e.x * a1) / (a2 - a1), (s.y * a2 - e.y * a1) / (a2 - a1));
}
}st, lt;
int n, m, h, k;
bool cmp(Point a, Point b) {
return st.s.dis(a) < st.s.dis(b);
}
bool check(Point x) {
return (sgn(max(st.e.x, st.s.x) - x.x) >= 0 && sgn(min(st.e.x, st.s.x) - x.x) <= 0 && sgn(max(st.e.y, st.s.y) - x.y) >= 0 && sgn(min(st.e.y, st.s.y) - x.y) <= 0);
}
void solve() {
scanf("%d%d", &n, &m);
scanf("%lf%lf%lf%lf", &st.s.x, &st.s.y, &st.e.x, &st.e.y);
for(int i = 1; i <= n; ++ i) scanf("%lf%lf", &p[i].x, &p[i].y);
while (m --) {
scanf("%d%d", &h, &k);
for(int i = 1; i <= n; ++ i) {
if(i != h) {
lt.s = p[h];
lt.e = p[i];
Point temp = st.crosspoint(lt);
if(check(temp)) _p[++pos] = st.crosspoint(lt);
}
}
sort(_p + 1, _p + 1 + pos, cmp);
if(pos < k) printf("-1\n");
else _p[k].out();
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
//freopen("out.txt", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
solve();
#endif
return 0;
}