标签:return otherwise 64bit esc span with efi output rect
Fruit Ninja
时间限制:C/C++ 5秒,其他语言10秒
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 ≤ 10000) 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(-1000000000<=xi,yi<=1000000000),denotes the coordinates of a fruit.
输出描述:
For each test case, output "Yes" if there are at least one EXCELLENT touch. Otherwise, output "No".
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
题目:n个点,问是否至少有n*x个点在一条直线上。
对于极限数据n=10000,x=0.1的情况,分析发现我们若是随机选取一个点,选到这条直线上的点的概率是1/10,反之选不到的概率就是9/10。
那这样我们选取n次,选不到的概率就是(9/10)的n次方。当n较大时,这个概率就足够低,可以让我们通过这个题。
#include <bits/stdc++.h> #define N 1000000007 using namespace std; long double check[10050]; int x[10050],y[10050]; int main() { int t; scanf("%d",&t); while(t--) { int n,c1=0,up,ans=0; double xx; scanf("%d %lf",&n,&xx); up=ceil(xx*1.0*n); for(int i=1; i<=n; i++)scanf("%d %d",&x[i],&y[i]); for(int i=1; i<=min(20,n-up+1); i++) { c1=0; for(int j=1; j<=n; j++) if(i!=j) { if(x[j]!=x[i])check[c1++]=(y[j]-y[i])*1.0/(x[j]-x[i]); else check[c1++]=N; } sort(check,check+c1); int tot=1; check[c1]=N+1; for(int i=1; i<=c1; i++) { if(check[i]!=check[i-1]) { ans=max(ans,tot+1); tot=1; } else tot++; } if(ans>=up) { break; } } if(ans>=up) { printf("Yes\n"); } else { printf("No\n"); } } return 0; }
标签:return otherwise 64bit esc span with efi output rect
原文地址:https://www.cnblogs.com/tian-luo/p/9426389.html