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 StepByStepCnmLife at 2015-05-09 22:30:43 on Problem 1106
#include <stdio.h>
#include <math.h>
#define MAXNUM  1000
typedef struct Point{
    int x;
    int y;
}Point;
void change_origin(Point *set,int n,Point origin)
{
    int i;
    for(i=0;i<n;i++)
    {
        set[i].x-=origin.x;
        set[i].y-=origin.y;
    }
}
double cross(Point a,Point b)
{
    return a.x*b.y-b.x*a.y;
}
int main()
{
    Point  set[MAXNUM];
    Point  origin;
    int    a,b,n,max,i,j;
    double radius;
    while(scanf("%d %d %lf",&origin.x,&origin.y,&radius))
    {
        if(radius<0)break;
        scanf("%d",&n);
        for(i=0,j=0;i<n;i++)//得到一个园内的点集,j代表点集个数
        {
            scanf("%d %d",&a,&b);
            if( ((a-origin.x)*(a-origin.x)
                +(b-origin.y)*(b-origin.y)-radius*radius)<=0 )
            {
                set[j].x=a,set[j].y=b;
                j++;
            }
        }
        n=j;
        change_origin(set,j,origin);
        max=0;
        for(i=0;i<n;i++)
        {
            j=i+1;
            a=1;
            while((j-i)<n)
            {
                if(cross(set[i],set[j%n])>=0)a++;//这里a用来存储满足条件点的个数
                j++;
            }
            max=max>a?max:a;
        }
        printf("%d\n",max);
    }
    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