CC MSTONES(Milestones-概率)

来源:互联网 发布:苹果改铃声软件 编辑:程序博客网 时间:2024/06/16 12:31

Milestones

Problem code: MSTONES

All submissions for this problem are available.

Once upon a time, there was a Kingdom of Seven Roads. Besides a fancy name, it actually had exactly 7 straight roads. Its residents wanted to keep track of the distances they traveled so they placed milestones along some roads. The roads slowly deteriorated and disappeared but some milestones remained. Archeologists documented remaining milestones and want to reconstruct the kingdom, starting with its main road. Help them by finding the maximum number of collinear milestones.

Input

The first line contains a single integer T, the number of test cases. The first line of each testcase contains the number of documented milestones N. Following lines give the coordinates (Xi, Yi) of those milestones. Coordinates of all milestones will be different.

Output

For each test case, output the maximum number of collinear milestones.

Constraints

  • T <= 30
  • 1 <= N <= 10 000
  • -15 000 <= Xi, Yi <= 15 000

Example

Input:250 01 02 01 13 121 110 10Output:32

Author:thocevarTester:subraEditorialhttp://discuss.codechef.com/problems/MSTONESTagsfeb11 hard thocevarDate Added:12-12-2010Time Limit:5 secSource Limit:50000 BytesLanguages:ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.8.1, CPP11, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • SUBMIT


题目大意:给若干点,它们可被7条直线覆盖,求在同一直线上的点的最大个数

解法:由题意可知这条直线最少覆盖n/7个点,否则那7条直线不可能覆盖点集。

如果我们随便取2个点,它们连成1条直线,则它是答案的概率=(1/7)^2=1/49

随便取K次,都不是答案的概率=(48/49)^K K=200时,数值很小,基本可以断定。




#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXT (30+10)#define MAXN (10000+10)long long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}typedef long long ll;int T,n;int x[MAXN],y[MAXN];bool is_out(int i,int j,int k){int X1=x[i]-x[j],Y1=y[i]-y[j];int X2=x[i]-x[k],Y2=y[i]-y[k];return X1*Y2-X2*Y1;}int rand(int n){return rand()%n+1;}int main(){//freopen("MileStones.in","r",stdin);//freopen("MileStones.out","w",stdout);scanf("%d",&T);For(t,T){scanf("%d",&n);For(i,n) scanf("%d%d",&x[i],&y[i]);int K=200,ans=0;if (n<=2) {printf("%d\n",n);continue;}while(K--){int i=rand(n),j=rand(n),tot=0;while (i==j) i=rand(n),j=rand(n);For(k,n)if ((k^i)&&(k^j)) tot+=is_out(i,j,k);ans=max(ans,n-tot);}printf("%d\n",ans);}return 0;}



0 0