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

这也太坑爹了吧····一个判断,加了0ms 不加就TLE````

Posted by 13477061482 at 2011-07-29 19:51:28 on Problem 3278
#include <stdio.h>
#include <math.h>
#define queue_size 300000

typedef struct
{
	int num;
	int step;
}flag_int;

typedef struct 
{
	int front;
	int rear;
	flag_int data[queue_size];
}cir_queue;


int visit[queue_size];
cir_queue cq;
void en_queue(int e,int step);
flag_int de_queue();
void main()
{
	int x,y;
	flag_int mid;
	scanf("%d%d",&x,&y);
	if(x>y)
		printf("%d\n",x-y);
	else
	{
		cq.front=cq.rear=0;
		en_queue(x,0);
		while(1)
		{
			if(cq.data[cq.front].num==y)
				break;
			else if(cq.data[cq.front].num>y)
			{
				mid=de_queue();
				if(visit[mid.num-1]!=611) //就是这句话!!! 当n大于k的时候肯定只有减1了···  我这句话没有加一直TLE  我想不通的是 就算不加这句话   也才多了一个要考虑的数!!! 但是下面的判断是一直都在的。真是太坑爹了···加了就0ms 不加就TLE
					en_queue(mid.num-1,mid.step+1);
			}
			else
			{
				mid=de_queue();
				if(visit[mid.num+1]!=611)
					en_queue(mid.num+1,mid.step+1);
				if(visit[mid.num-1]!=611)
					en_queue(mid.num-1,mid.step+1);
				if(visit[mid.num*2]!=611)	
					en_queue(mid.num*2,mid.step+1);
			}
		}
		printf("%d\n",cq.data[cq.front].step);
	}
}

void en_queue(int e,int step)
{
	if(e<=queue_size)
	{
		visit[e]=611;
		cq.data[cq.rear].num=e;
		cq.data[cq.rear].step=step;
		cq.rear=(cq.rear+1)%queue_size;
	}
}

flag_int de_queue()
{
	flag_int he;
	he.num=cq.data[cq.front].num;
	he.step=cq.data[cq.front].step;
	cq.front=(cq.front+1)%queue_size;
	return (he);
}


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