列表

详情


NC220444. Mr.MainandWindmills

描述

Mr. Main took a train from city to city and passed a plain full of windmills. The train ran in a straight line. A windmill is a machine used for wind power generation. Its fan blades rotate when the wind blows. From his perspective, colorful windmills lined up on the horizon from left to right.
 
As the train was running, the order of windmills from his perspective was constantly changing: a windmill was originally on the left/right of another, and then changed to its right/left; 

Given the coordinates of the windmills, please find the coordinate of him when he just observed the -th windmill exchanged order with other windmills for the -th times. It is guaranteed that any three of the points given, the cities and the windmills, were not collinear, and that all of the windmills were on the same side of the line that the train ran along.



As shown in the picture, in Mr. Mian's perspective, B was initially to the left of A, and later to the right of A.

输入描述

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 x_s, y_s, x_t and y_t (), 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 x_i,
y_i (), which are the coordinates of the -th windmill.

The next lines describe the queries, the -th of which contains two integers, h_i and k_i (), denoting a query for the coordinates when observing the k_i-th pass of the h_i-th windmill.

输出描述

Output m lines, each containing two real numbers x_i, y_i, representing the coordinates when the h_i-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));
		}
	}
}

上一题