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

最新发现.~~~....请HAWK解释一下.

Posted by cannie at 2005-10-19 12:13:23 on Problem 2514
In Reply To:请大牛解释一下~为什么用g++ long long就RUNTIME ERROR, c++ __int64 就AC, 如果比赛碰到这种问题,还不栽了..... Posted by:cannie at 2005-10-18 23:47:00
#include <stdio.h>
#include <math.h>
#include <iostream.h>
long long finda(long long k){
	char s[30];
	long long tot, i, res, m;
	long long d[30] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
				 100000000, 1000000000};
	tot = 0;
	for (i = 1;; i++){
//if (i >= 29) while (1);
		if (tot + i * (d[i+1] - d[i]) >= k - tot)
			break;
		tot = tot + i * (d[i+1] - d[i]);
	}
	res = k - tot;
	m = (res - 1) % i;
	res = (res - 1) / i;
	res += d[i];
	sprintf(s, "%lld", res);
	return s[m] - '0';
}
long long findb(long long k){
	char s[30];
	long long tot, i, res, m;
	long long d[30] = {0, 1, 4, 10, 32, 100, 317, 1000, 3163, 10000, 31623,
				 100000, 316228, 1000000, 3162278, 10000000, 31622777,
				 100000000, 316227767, 1000000000};
	tot = 0;
	for (i = 1;; i++){
//if (i >= 29) while (1);
		if (i * (d[i+1] - d[i]) >= k - tot)
			break;
		tot = tot + i * (d[i+1] - d[i]);
	}
	res = k - tot;
	m = (res - 1) % i;
	res = (res - 1) / i;
	res += d[i];
	sprintf(s, "%lld", res * res);
	return s[m] - '0';
}
int main(){
	long long k, res, tmp;
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
k = 0;                        /////////注意这:   如果把这句去了TLE,不去就WA............难道这也是程序问题????///////希望HAWK能够解释一下.
	while (scanf("%lld", &k) == 1 && k > 0){
if (k > 2147483647) while (1);
//if (k == 0) break;

		res = finda(k) + findb(k);
		k++;
		tmp = finda(k) + findb(k);
		while (tmp == 9){
			k++;
			tmp = finda(k) + findb(k);
		}
		if (tmp > 9)
			res ++;
		printf("%lld\n", res % 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