UVA 12009 - Avaricious Maryanna

47 篇文章 0 订阅
20 篇文章 0 订阅
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
const int maxn = 1111;
const int N = 1111;
const double eps = 1e-8;
int a[N], b[N], d[N];
int x[N], y[N];
void go(int i, int a[]) {
	int j, k, t;
	for (k = 0; k < 10; ++k) {
		t = a[i] + k * a[0] * 2;
		if (t % 10 == k) {
			for (j = 0; j < i; ++j)
				a[j + i] += a[j] * k * 2;

			a[i + i] += k * k;
			for (j = 0; j < maxn; ++j)
				a[j + 1] += a[j] / 10, a[j] %= 10;
			break;
		}
	}
}
void print(int n, int a[]) {
	if (!a[n - 1])
		return;
	putchar(' ');
	for (int i = n - 1; i >= 0; --i)
		printf("%d", a[i]);
}
int main() {
	ios::sync_with_stdio(false);
	a[0] = 5;
	b[0] = 6;
	a[1] = 2;
	b[1] = 3;
	int i, j, k, t;
	for (i = 1; i < 502; ++i) {
		go(i, a);
		go(i, b);
	}
	int T;
	scanf("%d", &T);
	for (int cas = 1; cas <= T; ++cas) {
		scanf("%d", &k);
		printf("Case #%d:", cas);
		if (k == 1)
			puts(" 0 1 5 6");
		else {
			t = 0;
			t += (a[k - 1] > 0);
			t += (b[k - 1] > 0);
			if (!t)
				puts("Impossible");
			else {
				t = 0;
				for (j = k - 1; j >= 0; --j) {
					if (a[j] < b[j])
						t = 1;
					if (a[j] > b[j])
						t = 2;
					if (t)
						break;
				}
				if (t == 1)
					print(k, a), print(k, b);
				if (t == 2)
					print(k, b), print(k, a);
				puts("");
			}
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值