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

Re:为什么老是WA呢? 是不是算法上的错误呢?(附有代码) 2452

Posted by tcxgsy at 2005-08-06 19:21:58
In Reply To:为什么老是WA呢? 是不是算法上的错误呢?(附有代码) Posted by:tcxgsy at 2005-08-06 19:21:26
> #define  M  1024
> #include"stdio.h"
> #include"math.h"
> 
> int Max(int a[M],int n)      //求出最大的位置函数。
> { int i,j=0;
>    int temp;
>     for(i=1;i<=n;i++)                                                  //进行比较,当一个数比其他的
>          {if(a[i]>a[i+1])                                              数据大时,就用用记时器,J++
>                        {temp=a[i+1];a[i+1]=a[i];a[i]=temp;             来所定这个大数和后者的交换次
>                            j++ ;                                       数,来知道它里后边多少位,来
>                         }                                              定位置。
>            else {j=0;continue;}
>           }
>   return(n-j);
> }
> int Min(int a[M],int n)                      //类似找最大的位置。
> {
> int i,j=0;
> int temp;
>     for(i=1;i<=n;i++)
>          {if(a[i]<a[i+1]) 
>                        {temp=a[i+1];a[i+1]=a[i];a[i]=temp;
>                            j++; 
>                         }
>            else {j=0;continue;}
>           }
>   return(n-j);
> }
> main()
> {int i,j,n;
>  int a[2][M];
>   int k,l;
>    scanf("%d",&n);            //控制输入的个数
>    for(i=0;i<2;i++)
>         for(j=1;j<=n;j++)             
>                scanf("%d",&a[i][j]);  //这是输入两组数据
>  
>   for(i=0;i<2;i++)
>        { k=Max(a[i],n);   // 调用函数,求出最大的位置。
>           l=Min(a[i],n);  // 调用函数,求出最小的位置。
>          if(k>l)
>                     printf("%d",k-l);
>              else  printf("-1");
>         } 
> } 

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