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

I really don't have any idea how to improve my program's effeciency :( Could anyone help me?

Posted by rouder at 2007-03-15 18:56:11 on Problem 2633
TLE..

#include<stdio.h>
#define INF 999999999
int n;
double m;
double f[8];
struct point
{
	double x;
	int win;
};
point a[50000];
int st;
int pointer[8];
double min;
double max;
int main()
{
	int i;
	int t, testcase;
	scanf("%d", &testcase);
	for(t=1;t<=testcase;t++)
	{
		scanf("%lf%d", &m, &n);
		for(i=1;i<=n;i++)
		{
			scanf("%lf", &f[i]);
			f[i]=1.0/f[i];
			pointer[i]=1;
		}
		st=1;
		a[1].x=1; a[1].win=0;
		while(a[st].x<m)
		{
			max=-1; min=INF;
			for(i=1;i<=n;i++)
			{
				while(a[pointer[i]].x*f[i]<=a[st].x) pointer[i]++;
				if(a[pointer[i]].win==0 && max<a[pointer[i]].x*f[i]) max=a[pointer[i]].x*f[i];
				if(min>a[pointer[i]].x*f[i]) min=a[pointer[i]].x*f[i];
			}
			if(max!=-1)
			{
				st++; a[st].x=max; a[st].win=1;
				if(a[st-1].win==1){a[st-1].x=a[st].x; st--;}
			}
			else
			{
				st++; a[st].x=min; a[st].win=0;
				if(a[st-1].win==0){a[st-1].x=a[st].x; st--;}
			}
		}
		while(m<a[st-1].x) st--;
		if(a[st].win==0) printf("Mikael\n");
		else printf("Nils\n");
	}
	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