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 nuciedh at 2007-02-13 12:22:05 on Problem 3104
#include <iostream>
#include <fstream>
const int N = 100010;

using namespace std;

int n, k, a[N];

int attempt (int l, int r)
{
    int i, b, t, s;
    int tmp;
    if (l < r)
    {
          s = 0;
          t = (l + r) / 2;
          for (i = 0; i < n; i ++)
          {
              tmp = a[i];
              tmp -= t;
              if (tmp > 0)
              {
                  s += (tmp + k - 2) / (k - 1);
              }
          }
          if (s <= t)
          {
                b = attempt (l, t);
          }
          else
          {
              b = attempt (t + 1, r);
          }
          return b;
    }
    else
    {
        return r;
    }
}

void solve ()
{
     int i, tmp;
     for (tmp = 0, i = 0; i < n; i ++)
     {
         scanf ("%d", &a[i]);
         if (a[i] > tmp)
         {
                  tmp = a[i];
         }
     }
     scanf ("%d", &k);
     if (k > 1)
     {
          printf ("%d\n", attempt (1, tmp));
     }
     else
     {
         printf ("%d\n", tmp);
     }
}

int main ()
{
    while (EOF != scanf ("%d", &n))
    {
          solve ();
    }
    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