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 KatrineYang at 2016-09-01 12:23:10 on Problem 1248
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

bool compare(int x, int y){
	return x>y;
}


int main() {
	int n; string s;
	while(1){
		cin >> n >> s;
		if(n == 0) break;
		int gs = s.length();
		int digit[14];
		for(int i = 0; i < gs; i++){
			digit[i] = s[i] - 'A' + 1;
		}
		sort(digit, digit+gs, compare);
		bool used[14] = {0};
		int rec[5];
		int sum = 0;
		bool ky = 0;
		for(int i = 0; i < gs; i++){
			used[i] = 1;
			rec[0] = digit[i];
			sum += digit[i];
			for(int j = 0; j < gs; j++){
				if(used[j]) continue;
				used[j] = 1;
				rec[1] = digit[j];
				sum -= digit[j]*digit[j];
				for(int k = 0; k < gs; k++){
					if(used[k]) continue;
					used[k] = 1;
					rec[2] = digit[k];
					sum += digit[k]*digit[k]*digit[k];
					for(int l = 0; l < gs; l++){
						if(used[l]) continue;
						used[l] = 1;
						rec[3] = digit[l];
						sum -= digit[l]*digit[l]*digit[l]*digit[l];
						for(int m = 0; m < gs; m++){
							if(used[m]) continue;
							sum += digit[m]*digit[m]*digit[m]*digit[m]*digit[m];
							if(sum == n){
								rec[4] = digit[m];
								ky = 1;
								goto done;
							}
							sum -= digit[m]*digit[m]*digit[m]*digit[m]*digit[m];
						}
						used[l] = 0;
						sum += digit[l]*digit[l]*digit[l]*digit[l];
					}
					used[k] = 0;
					sum -= digit[k]*digit[k]*digit[k];
				}
				used[j] = 0;
				sum += digit[j]*digit[j];
			}
			used[i] = 0;
			sum -= digit[i];
		}
		done:
		if(ky){
			for(int i = 0; i < 5; i++){
				cout << (char)('A'-1+rec[i]);
			}
		}
		else{
			cout << "no solution";
		}
		cout << endl;
	}
	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