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 houxuanfelix at 2006-07-15 13:47:26 on Problem 1666
#include <stdio.h>

int  cmp(int num[],int n)
{
     int  flag=0,i;
     for (i=0;i<n-1;i++)
          if (num[i]!=num[i+1])
          {
               flag=1;
               break;
          }
     return   flag;
}

int   num[100000];

int main()
{
    int  i,j,k,m,n,t,count;
    while (scanf ("%d",&n)!=EOF&&n!=0)
    {
          count=0;
          for (i=0;i<n;i++)    scanf ("%d",&num[i]);
          t=cmp(num,n);
          if (t==0)
          {
              printf ("%d %d\n",count,num[0]);
          }
          else
          while (1)
          {
              count++;
              m=num[0];
              for (i=1;i<n;i++)
              {
                k=num[i];
                num[i-1]+=k/2;
                num[i]=k/2;
              }      
              num[n-1]+=m/2;
              num[0]-=m/2;
              t=cmp(num,n);
              if (t==0)
              {   
                   printf ("%d %d\n",count,num[0]);
                   break;
              }
              else
              {
                   for (i=0;i<n;i++)
                      if (num[i]%2==1)
                          num[i]++;
                   t=cmp(num,n);
                   if (t==0)
                   {   
                        printf ("%d %d\n",count,num[0]);
                        break;
                   }
              }
          }
    }
    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