NC220444. Mr.MainandWindmills
描述
输入描述
The first line of input contains two integers and , where is number of windmills, and is number of queries.
The second line contains four integers , , and (), which are the coordinates of the starting city s and destination city t.
The next lines describe the windmills, the -th of which contains two integers ,
(), which are the coordinates of the -th windmill.
The next lines describe the queries, the -th of which contains two integers, and (), denoting a query for the coordinates when observing the -th pass of the -th windmill.
输出描述
Output m lines, each containing two real numbers , representing the coordinates when the -th windmill is observed to exchange order with other windmills for k times; if it does not exist, output -1. Your answer is considered correct if its absolute or relative error with the standard answer is less than .
示例1
输入:
4 2 0 0 5 0 1 3 2 4 4 1 4 5 1 2 3 2
输出:
-1 4.6666666667 0.0000000000
C++(clang++11) 解法, 执行用时: 42ms, 内存消耗: 3364K, 提交时间: 2021-04-07 21:52:42
#include<bits/stdc++.h> using namespace std; int n, m, h, k; double x[1234], y[1234], xs, ys, xt, yt, t; vector<double>ans[1234]; int main() { cin >> n >> m >> xs >> ys >> xt >> yt; for(int i = 0; i < n; i++) cin >> x[i] >> y[i]; for(int i = 0; i < n; i++) { for(int j = i + 1; j < n; j++) { t = ys*(x[i]-x[j]) + xs*(y[j]-y[i]) + x[j]*y[i] - x[i]*y[j]; t /= (xt-xs) * (y[i]-y[j]) + (yt-ys) * (x[j]-x[i]); if(t > 0 && t < 1) { ans[i].push_back(t); ans[j].push_back(t); } } sort(ans[i].begin(), ans[i].end()); } while(m--) { cin >> h >> k; if(ans[h-1].size() < k) puts("-1"); else { t = ans[h-1][k-1]; printf("%.6f %.6f\n", xs + t*(xt-xs), ys + t*(yt-ys)); } } }