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

救命啊!!!!!实在想不出怎么错啦

Posted by smilezhen at 2005-08-24 19:36:10 on Problem 2249
#include <iostream.h>

int main(void){
	int n, k, *a, *b, sum, i, j;
	cin >> n >> k;
	while(n!=0 && k!=0){
		if(k==0 || k == n) cout << 1<< endl;
		else if(k ==1 || k == n-1) cout << n << endl;
		else{
			if(k>n/2) k = n-k;
			a = new int[k];
			b = new int[k];
			
			for(i=0; i<k; ++i){
				a[i] = n-i;
				b[i] = i+1;
			}
			
			sum = 1;
			for(i=0; i<k; ++i){
				for(j=k-1; j>0; j--){
					if(a[i]%b[j] == 0 && b[j]!=1){
						a[i] /= b[j];
						b[j] = 1;
					}
				}
				sum *= a[i];
				for(j=k-1; j>0; j--){
					if(sum%b[j] == 0 && b[j]!=1){
						sum /= b[j];
						b[j] = 1;
					}
				}
			}
			delete []a;
			delete []b;

			cout << sum << endl;
		}
		cin >> n >> k;
	}
	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