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 dinysirius at 2009-04-16 23:56:31 on Problem 2245
#include <iostream>
using namespace std;

class P{
	public :
		int pos[6];
		int number[14];
		int n;
		
		P(){};
		
		void init(){

			for(int i = 0 ; i < 6 ; i ++ ){
				
				pos[i] = i;	
			}	
		}
		friend istream & operator >> (istream &in,P &op){
			
			for(int i = 0 ; i < op.n ; i ++ ){
				
				cin >> op.number[i];	
			}
			return in;
		}
		
		friend ostream & operator << (ostream &out,P &op){
			
			for(int i = 0 ; i < 5 ; i ++ ){
				
				out << 	op.number[op.pos[i]] << " ";
			}	
			out << op.number[op.pos[5]] << endl;
			
			return out;
		}
};

void cp(P &p){
	
	cout << p;
	
	while(p.pos[0] != p.n - 6){
		
		int pp = 0;
		
		for(int i = 5 ; i >= 0 ; i -- ){
			
			if(p.pos[i] != p.n - 6 + i){
				
				pp = i;
				break;	
			}	
		}	
		int k = p.pos[pp] + 1;
		
		for(int i = pp ; i <= 5 ; i ++ ){
			
			p.pos[i] = k ++;
		}

		if(p.pos[5] == p.n)
			continue;
			
		cout << p;
	}
	cout << endl;	
}

int main(){
	
	P p;
	
	while(scanf("%d",&p.n) && p.n){
		
		p.init();
		
		cin >> p;
		
		cp(p);
	}	
	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