随笔 - 147  文章 - 71  trackbacks - 0
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用链接

留言簿(1)

随笔分类(146)

随笔档案(147)

文章分类(28)

文章档案(28)

喜欢的Blog

搜索

  •  

最新评论

阅读排行榜

评论排行榜

http://acm.pku.edu.cn/JudgeOnline/problem?id=1118
【题意简述】在点集中求一条直线,使其经过的点数最多,输出该点数。
【分析】O(n^3)暴力搜索,方法类似福建师范大学的2060(Accept)。
import java.util.*;
import java.io.*;

public class poj_1118{
    
    
public static void main(String rgs[]) throws Exception
    
{
        Scanner cin 
= new Scanner(new BufferedInputStream(System.in));
        
int i,j,k,n = cin.nextInt();
        
while(n!=0){
            
int[] x=new int[n];
            
int[] y=new int[n];
            
for(i=0;i<n;i++){
                x[i] 
= cin.nextInt();
                y[i] 
= cin.nextInt();
            }

            
int count,flag,max=2,t1=0,t2=0;
            
for(i=0;i<n-1;i++){
                
for(j=i+1;j<n;j++){
                    count
=2;
                    
// 斜率不存在
                    if(x[j]-x[i]==0)
                        flag
=1;
                    
// 斜率是0
                    else if(y[j]-y[i]==0)
                        flag
=2;
                    
else{
                        flag
=3;
                        t1
=y[j]-y[i];
                        t2
=x[j]-x[i];
                    }

                    
for(k=0;k<n;k++){
                        
if(k!=&& k!=j){
                            
switch(flag){
                                
case 1:if(x[k]-x[i]==0) count++;break;
                                
case 2:if(y[k]-y[i]==0) count++;break;
                                
case 3:if(t1*(x[k]-x[i])==t2*(y[k]-y[i])) count++;break;
                            }
                            
                        }

                    }

                    
if(count>max)
                        max
=count;
                }

            }

            System.out.println(max);
            n 
= cin.nextInt();
        }

    }

}
posted on 2009-09-13 09:54 飞翔天使 阅读(700) 评论(0)  编辑  收藏 所属分类: poj

只有注册用户登录后才能发表评论。


网站导航: