usaco.section1.2.Dual Palindromes

本文介绍了一种算法,用于找出大于给定数值s的所有数中,在两种或两种以上不同进制(2到10进制)下为回文串的数。通过逐个检查每个数在各进制下的表示是否为回文串来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

找到 n 个 比 s 大的,在两种或两种以上的进制( 2 - 10 进制 )下是回文串的数,并输出出来

#include <cstdio>

using namespace std;

int main()
{
	freopen("dualpal.in", "r", stdin);
	freopen("dualpal.out", "w", stdout);
	int n, s, t = 0, num;
	scanf("%d%d", &n, &s);
	while(t < n){
		s ++; 
		int cnt = 0, a[100], tot = 0;
		for(int k = 2; k <= 10; k ++){
			num = s; tot = 0;
			while(num){
				a[++ tot] = num % k;
				num /= k;
			}// printf("%d ", k);
		//	for(int i = tot; i >= 1; i --) printf("%d ", a[i]); printf("\n");
			bool ok = 1;
			for(int i = tot; i >= 1; i --) if(a[i] != a[tot - i + 1]) { ok = 0; break; }
			if(ok) cnt++;
			if(cnt >= 2) { printf("%d\n", s); t ++; break; }
		}
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值