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-25 11:32:58 on Problem 2249
In Reply To:救命啊!!!!!实在想不出怎么错啦 Posted by:smilezhen at 2005-08-24 19:36:10
#include <iostream.h>

int main(void){
	int n, k, *a, *b, i, j;
	double sum;
	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;
			}

			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;
					}
				}
			}
			
			i=0;
			while(a[i] == 1) i++;
			sum = a[i];
			for(j=0; j<k; ++j){
				if(b[j] != 1)
					sum /= b[j];
			}
			i++;
			for(; i<k;++i){
				if( a[i] != 1)
					sum *= a[i];
			}

			delete []a;
			delete []b;

			cout << (int)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