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

怎么做才能不tle呢?

Posted by gemenhao at 2006-06-14 13:08:24 on Problem 1117
In Reply To:Re:怎么做才能不tle呢? Posted by:bobpkuhj at 2004-06-27 11:14:42
正解
对于方程 11 x + y = n;
y是个位数.
if n % 11 == 10;
方程无解
int posn(int n)
{
	int y = n % 11;
	int x = n / 11;
	return y < 10 ? 10 * x + y : -1;
}

然后枚举不同数所在位置
		base = 10;
		while (base <= n)
		{
			int tn   = n / base;
			int last = n % base;
			r = posn(tn);
			r = r * base + last / 2;
			if (r*2 > n)
				fill(a,t,r);

			r = posn(tn - 1);
			r = r * base + (last + base) / 2;
			if (r*2 > n)
				fill(a,t,r);
			base *= 10;
		}

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