链接:https://www.nowcoder.com/acm/contest/163/A
来源:牛客网
Fruit Ninja is a juicy action game enjoyed by millions of players around the world, with squishy,
splat and satisfying fruit carnage! Become the ultimate bringer of sweet, tasty destruction with every slash.
Fruit Ninja is a very popular game on cell phones where people can enjoy cutting the fruit by touching the screen.
In this problem, the screen is rectangular, and all the fruits can be considered as a point. A touch is a straight line cutting
thought the whole screen, all the fruits in the line will be cut.
A touch is EXCELLENT if ≥ x, (N is total number of fruits in the screen, M is the number of fruits that cut by the touch, x is a real number.)
Now you are given N fruits position in the screen, you want to know if exist a EXCELLENT touch.
输入描述:
The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
The first line of each case contains an integer N (1 ≤ N ≤ 104) and a real number x (0 < x < 1), as mentioned above.
The real number will have only 1 digit after the decimal point.
The next N lines, each lines contains two integers xi and yi (-109 ≤ xi,yi ≤ 109), denotes the coordinates of a fruit.
输出描述:
For each test case, output "Yes" if there are at least one EXCELLENT touch. Otherwise, output "No".
示例1
输入
复制
2
5 0.6
-1 -1
20 1
1 20
5 5
9 9
5 0.5
-1 -1
20 1
1 20
2 5
9 9
输出
复制
Yes
No
这 竟然 要跑随机数,
不过 想来也是 x在0-1 之间, 求画一条直线,然后经过的点 最大 为 cot 如果 cot /n >= x 则 yes
没有的话 就no
n在 10000 内 跑随机数 多跑几次 , 跑出一条在 n 内的直线, 然后 判断共线.
hen'q很强很强 学习了/
[代码]
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i = n;i>=a;i--)
#define Si(x) scanf("%d",&x)
#define Pi(x) printf("%d\n",x)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const int maxn = 1e5+10;
using namespace std;
struct node{
int a,b;
}p[maxn];
int operator * (node p1,node p2)
{
return (p1.a*p2.b - p2.a*p1.b);
}
node operator - (node p1,node p2)
{
return node{p1.a-p2.a,p1.b-p2.b};
}
int main()
{
srand(time(0));
int n;
double k;
int t;
Si(t);
while(t--)
{
memset(p,0,sizeof(p));
Si(n);
scanf("%lf",&k);
rep(i,1,n)
{
scanf("%d %d",&p[i].a,&p[i].b);
}
int flag = 0;
for(int i = 0 ; i <600 && !flag ;i++)
{
int a = rand()%n, b = rand()%n;
if( a==b)
continue;
int cot = 0;
for(int j = 1 ;j<=n;j++)
{
if( (p[j]-p[a])*(p[j]-p[b])==0)
{
cot++;
}
}
if( cot >= k*n)
{
flag =1;
break;
}
}
printf(flag ==1 ?"Yes\n":"No\n");
}
return 0;
}