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

Re:如果是高精度怎么办?能不能提供点代码?

Posted by taesimple at 2011-08-10 19:17:46 on Problem 1306
In Reply To:如果是高精度怎么办?能不能提供点代码? Posted by:zhyzhang at 2009-05-20 21:47:50
比较弱
#include <stdio.h>
int a[200];
int size = 0, cur, last;
void mul(int b){
	int cf = 0;
	for(int i = 0; i < 200; i++){
		a[i] = a[i]*b+cf;
		cf = a[i]/10;
		a[i] %= 10;
	}
	for(int i = size; i < 200; i++)
		if(a[i] != 0) size++;
}
void div(int b){
	last = 0;
	int i;
	for(i = size-1; i >= 0; i--){
		cur = last*10+a[i];
		if(cur < b){
			a[i] = 0;
			last = cur;
		}
		else{
			a[i] = cur/b;
			last = cur%b;
		}
	}
	for(i = size-1; i >= 0; i--)
		if(a[i] != 0) break;
	size = i+1;
}
int main(){
	int n, m;
	while(1){
		scanf("%d%d", &n, &m);
		if(n == 0 && m == 0) break;
		for(int i = 0; i < 200; i++)
			a[i] = 0;
		a[0] = size = 1;
		for(int i = n-m+1; i <= n; i++) mul(i);
		for(int i = 2; i <= m; i++) div(i);
		printf("%d things taken %d at a time is ", n, m);
		for(int i = size-1; i >= 0; i--)
			printf("%d", a[i]);
		printf(" exactly.\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