列表

详情


NC236061. Laser Trap

描述

BaoBao is playing the famous gameElden Ringthese days. It's an open-world game in which you can control your character to travel from places to places. However, your character could also enter a trap and you need to figure out how to escape. Right now, BaoBao's character is stuck in a 2-dimensional plane with deadly lasers. There are n laser generators (each can be regarded as a point) shooting laser beams between every pair of them (so there are laser beams in total). The beams start and end at generator points and do not stretch to infinity.
Starting at point (0,0), BaoBao wants to escape to point without touching any laser beam or generator. In order to do so, BaoBao can ask her friend DreamGrid to remove any number of laser generators, together with any laser beam that starts or ends at these generators. Output the minimum number of laser generators that need to be erased for the escape.
Note that BaoBao does not need to move in a specific direction to escape. Her escaping route can even be a curve if necessary.

输入描述

There are multiple test cases. The first line of the input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer n () indicating the number of laser generators.
For the following n lines, the i-th line contains two integers x_i and y_i () indicating the location of the i-th laser generator.
It is guaranteed that no two generators coincide, and no laser beam or generator will touch (0,0).
It is also guaranteed that the sum of n of all test cases will not exceed .

输出描述

For each test case output one line containing one integer indicating the minimum number of generators that need to be removed.

示例1

输入:

3
2
1 0
2 0
3
1 0
0 1
-1 -1
5
2 -1
1 2
-1 2
-2 -1
0 -2

输出:

0
1
2

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 1335ms, 内存消耗: 31712K, 提交时间: 2022-04-09 16:49:48

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
const long double pi=acosl(-1);

int n;
long double a[(int)2e6+9];
int main(){
	int cse;cin>>cse;
	while(cse--){
		cin>>n;
		rep(i,1,n){
			int u,v;cin>>u>>v;
			a[i] = atan2l(1.0*v,1.0*u);
		}
		sort(a+1,a+1+n);
		rep(i,1,n) a[i+n]=a[i]+2*pi;
		int j=1,ans=1e9;
		rep(i,1,n){
			while(j<=(n<<1)&&a[j] - a[i] < pi) j++;
			ans=min(ans,j-i-1);
		}
		cout<<ans<<endl;
	}
	return 0;
}

上一题