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

帮忙看一下呀??WA!!!

Posted by ecjtubaowp at 2007-03-17 16:35:39 on Problem 2595
//5 -1 -1 4 3 1 1 0 3 4 0
#include<stdio.h>
#include<math.h>
#include<Limits.h>
#define fun1(a,b) a>b?b:a
#define fun2(a,b) a>b?a:b
typedef struct
 {
  int x;
  int y;
}POINT;
POINT point[50005],a[50005],pos1[10],pos2[10], *temp, source, small;
int k;
void Find(int n)
{
  int i, mult;
  temp = &point[0];
  for(i=1; i<n; i++)
  {
    if(point[i].y<temp->y||(point[i].y==temp->y&&point[i].x<temp->x))
        temp=&point[i];
  }
  return;
}
int Mult(POINT a, POINT b)
{
  return (a.x*b.y - b.x*a.y);//比较斜率//叉积.
}
double Dis(POINT k)
{
  return sqrt((k.x)*(k.x)+(k.y)*(k.y));
}
int MultBigger(POINT a, POINT b, POINT c)
{
  POINT p, q;
  p.x = b.x-a.x;
  p.y = b.y-a.y;
  q.x = c.x-b.x;
  q.y = c.y-b.y;
  if(Mult(p,q) < 0) return 1;/*叉积运算*///斜率最小原则
  else if(Mult(p,q) > 0) return 0;
  else
  {
    if(Dis(q)>Dis(p)) return 1;
    else return 0;
  }
}
int Search(int n)
{
  int i;
  POINT temper;//source = *temp; small = *temp;
  temper=source;
  for(i=0; i<n; i++)
  {
    if(point[i].x ==INT_MAX)//已检查过的点 
        continue;
    if (MultBigger(source,temper,point[i]))
    {
        temp=&point[i];
        temper=point[i];
    }
  }//for
  if(MultBigger(source, temper, small)) return 1;//回到初始点 
  a[k].x=temp->x;a[k].y=temp->y;k++;//回到初始点时source和temper相同.
  source=*temp;
  temp->x=INT_MAX;
  return 0;
}
int main()
{
  int n, i, c,j,m,D,D1,D2,m0,n0;
  double x1,y1,x2,y2,x3,y3,x4,y4;
  double min,max;
  while(scanf("%d%d",&n,&c)!=EOF)
  {
    for(i=0;i<n;i++)
    scanf("%d",&point[i].x);
    for(i=0;i<n;i++)
    scanf("%d",&point[i].y);
    if(n==1)
    {
     printf("%d.000 %d.000\n",point[0].y,point[0].y);
     continue;
    }
    Find(n);         /*找出最下、最右点*/
    source = *temp;
    small = *temp;
    //printf("%d %d\n",small.x,small.y);
    k=0;
    k++;
    a[k].x=small.x;a[k].y=small.y;k++;
    temp->x=INT_MAX;
    //printf("%d\n",temp->x);
    for(i=0;i<n;i++)
    if(Search(n))break;/*按叉积搜索 break 时回到出发点*/
    //printf("%d\n",k);
    //for(i=1;i<k;i++)
    //printf("%d %d\n",a[i].x,a[i].y);
    a[k].x=a[1].x;a[k].y=a[1].y;
    m0=n0=0;
    for(i=1;i<k;i++)
    {
     if(c>=a[i].x&&c<=a[i+1].x||c>=a[i+1].x&&c<=a[i].x)
     {m0++;n0++;
      pos1[m0].x=a[i].x;pos1[m0].y=a[i].y;pos2[n0].x=a[i+1].x;
      pos2[n0].y=a[i+1].y;
     }
    }
    //for(i=1;i<=2;i++)
    //printf("%d %d %d %d\n",pos1[i].x,pos1[i].y,pos2[i].x,pos2[i].y);
    if((pos2[1].x-pos1[1].x)!=0)
    min=(pos2[1].y-pos1[1].y)*(c-pos1[1].x)/(pos2[1].x-pos1[1].x)+pos1[1].y;
    else min=fun1(pos1[1].y,pos2[1].y);
    if((pos2[2].x-pos1[2].x)!=0)
    max=(pos2[2].y-pos1[2].y)*(c-pos1[2].x)/(pos2[2].x-pos1[2].x)+pos1[2].y;
    else max=fun2(pos2[1].y,pos2[2].y);
    printf("%.3lf %.3lf\n",min,max);
    }
}//main
/*
3 1
0 2 1
0 0 1
5 2
-1 4 1 0 4
-1 3 1 3 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