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 guojinyu at 2011-10-18 22:04:20 on Problem 3278
#include <iostream>
#include <cstdio>
using namespace std;
int n,k;
int dui[1000001],step[1000001];
void init()
{
  scanf("%d %d",&n,&k);
}
void solve()
{
  int head=0,tail=1;
  dui[head]=n;
  while(head!=tail)
  {
    if(dui[head]==k)
    {
      printf("%d",step[head]);
      break;
    }
    if(dui[head]<=k)
    {
      dui[tail]=dui[head]*2;
      step[tail]=step[head]+1;
      tail=(tail+1)%1000000;
    }
    dui[tail]=dui[head]-1;
    step[tail]=step[head]+1;
    tail=(tail+1)%1000000;
    if(dui[head]<=k)
    {
      dui[tail]=dui[head]+1;
      step[tail]=step[head]+1;
      tail=(tail+1)%1000000;
    }
    head=(head+1)%1000000;
  }
}
int main()
{
  init();
  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