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-07-17 09:20:07 on Problem 1117
首先是考虑写成AkB + AB的形式,其中k为去掉的数码,那么
2*B+(11*A+k)*10^b=N
对b煤局就行了,其中B小于10^b。但是有几个坑的地方
1,如果B是个0位数(即Ak+A)需要单独讨论
2,当B不是0位数时,N需要是偶数,而且一定要判断mod11是否是10,是10的话直接ignore因为k必须小于10
3,输出记得输出a和b的位数差个0,尤其是b=0需要特殊处理
4,记得排除掉结果中重复的数!因为对不同的去掉数位煤局可能得到同样的结果!!比如1222=1111+111,去掉哪一位都是一回事!我就是在这里WA了一次qaq
附代妈

#include <iostream>
#include <vector>
using namespace std;

int powOf10[10] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};

int ws(int n){
	for(int i = 1; i <= 9; i++){
		if(powOf10[i] > n) return i;
	}
	return 10;
}

int main() {
	int N;
	vector<int> res;
	cin >> N;
	if(N%11 != 10){
		int A = N/11;
		res.push_back(N-A);
	}
	if(N%2 == 0){
		for(int b = 1; powOf10[b] <= N; b++){
			int B = (N%powOf10[b])/2;
			int A11_K = (N-2*B)/powOf10[b];
			if(A11_K%11 != 10){
				int A = A11_K / 11;
				int k = A11_K % 11;
				res.push_back((10*A+k)*powOf10[b] + B);
			}
			if(N/powOf10[b] == 1) break;
			B = (powOf10[b] + N%powOf10[b])/2;
			A11_K = (N-2*B)/powOf10[b];
			if(A11_K%11 != 10){
				int A = A11_K / 11;
				int k = A11_K % 11;
				res.push_back((10*A+k)*powOf10[b] + B);
			}
		}
	}
	int gs = res.size();
	for(int i = 1; i < gs; i++){
		for(int j = i; j > 0; j--){
			if(res[j] > res[j-1]) break;
			int temp = res[j];
			res[j] = res[j-1];
			res[j-1] = temp;
		}
	}
	int gui = 0;
	int cnt = 0;
	for(int i = 0; i < gs; i++){
		if(res[i] == gui) continue;
		gui = res[i];
		cnt++;
	}
	cout << cnt << endl;
	int shou = 0;
	for(int i = 0; i < gs; i++){
		if(shou == res[i]) continue;
		shou = res[i];
		int wsA = ws(res[i]), wsB = ws(N - res[i]);
		cout << res[i] << " + ";
		for(int j = 0; j < wsA-wsB-1; j++) cout << 0;
		cout << N-res[i] << " = " << N << 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