现在的位置: 首页 > 综合 > 正文

USACO Section 1.2 Dual Palindromes

2019年04月07日 ⁄ 综合 ⁄ 共 733字 ⁄ 字号 评论关闭

大意略。

/*
ID:g0feng1
LANG:C++
TASK:dualpal
*/

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
using namespace std;

ofstream fout("dualpal.out");
ifstream fin("dualpal.in");

const int maxn = 100010;

int b[maxn];

int n, s;

void read_case()
{
	fin>>n>>s;
}

int check(int *a, int n)
{
	for(int i = 0; i < n/2; i++) if(a[i] != a[n-1-i]) return 0;
	return 1;
}

int change(int n, int base)
{
	int s = n;
	int len2 = 0;
	s = n;
	while(s)
	{
		int t = s % base;
		s /= base;
		b[len2++] = t;
	}
	if(check(b, len2)) return 1;
	return 0;
}

void solve()
{
	read_case();
	int tot = 0;
	for(int i = s+1; ; i++)
	{
		int ans = 0;
		for(int j = 2; j <= 10; j++)
		{
			if(change(i, j))
			{
				ans++;
				if(ans == 2)
				{
					tot++;
					fout<<i<<endl;
					break;
				}
			}
		}
		if(tot == n) break;
	}
	return ;
}

int main()
{
	solve();
	return 0;
}

抱歉!评论已关闭.