Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我彻底无语了!对这样的题目!

Posted by chenxuan123456789 at 2012-08-11 17:28:26 on Problem 1118
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<algorithm>
#define M 1000
#define eps 1e-8
#define INF 0xfffffff
using namespace std;

struct point 
{
int x,y;
}po[M];

int n;
double xl[M*M];

double solve(point a,point b)
{
if(a.x!=b.x)
{return (a.y-b.y)*1.0/(a.x-b.x);} 
else {return INF;}
}

int main()
{
int i,j,k;
int num,num1;
int maxn;
while(scanf("%d",&n)&&n)
{
for(i=0;i<n;i++)
scanf("%d%d",&po[i].x,&po[i].y);

maxn=-1;
for(i=0;i<n;i++)
{ 
k=0;num1=0;
for(j=i+1;j<n;j++)
{
double tmp=solve(po[i],po[j]);
if(fabs(tmp-INF*1.0)<eps)
num1++;//斜率不存在的情况 
else xl[k++]=tmp;
}
sort(xl,xl+k);
num=1;
for(j=1;j<k;j++)
{
if(xl[j]-xl[j-1]<eps)
num++;
else num=1;
if(num>maxn)
maxn=num;
}
if( num1>maxn)
maxn=num1; 
} 
printf("%d\n",maxn+1);
}
return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator