思路:先用随机数跑两个点,然后从已知的点集合中枚举,判断是否共线(利用斜率相同),找到满足条件M/N >= x 的M 即可
随机数真是个神奇的东东(`・ω・´)
AC代码:
#include<bits/stdc++.h>
#define rep(i,s,t) for(int i = (int)(s); i <= (int)(t); i++)
#define rev(i,t,s) for(int i = (int)(t); i >= (int)(s); i--)
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
const int maxn = 1e6+5;
struct Point
{
int x,y;
};
Point p[maxn];
bool judge_on_line(Point a,Point b,Point c)//斜率公式
{
return (c.x-a.x)*(b.y-a.y)==(b.x-a.x)*(c.y-a.y);
}
void init()
{
srand((unsigned)time(NULL));
}
int main()
{
#ifdef LOCAL_FILE
freopen("in.txt","r",stdin);
#endif // LOCAL_FILE
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
init();
int t;
cin>>t;
while(t--)
{
int n;
int flag = 1;
double x;
cin>>n>>x;
for(int i=1;i<=n;i++)
cin>>p[i].x>>p[i].y;
for(int i=0;i<250;i++)
{
int p1 = rand()%(n+1);
int p2 = rand()%(n+1);
if(p1 == p2) continue;
if(p1<1 || p2<1 || p1>n || p2>n) continue;
int m = 2;
for(int j=1;j<=n;j++)
{
if(j == p1 || j == p2) continue;
if(judge_on_line(p[p1],p[p2],p[j])) m++;
}
if((m*1.0/n) >= x)
{
flag = 0;
break;
}
}
if(flag)
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
}
return 0;
}