Ugly Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 14 Accepted Submission(s): 8
Special Judge
Problem Description
Everyone hates ugly problems.
You are given a positive integer. You must represent that number by sum of palindromic numbers.
A palindromic number is a positive integer such that if you write out that integer as a string in decimal without leading zeros, the string is an palindrome. For example, 1 is a palindromic number and 10 is not.
You are given a positive integer. You must represent that number by sum of palindromic numbers.
A palindromic number is a positive integer such that if you write out that integer as a string in decimal without leading zeros, the string is an palindrome. For example, 1 is a palindromic number and 10 is not.
Input
In the first line of input, there is an integer T denoting the number of test cases.
For each test case, there is only one line describing the given integer s ( 1≤s≤101000 ).
For each test case, there is only one line describing the given integer s ( 1≤s≤101000 ).
Output
For each test case, output “Case #x:” on the first line where x is the number of that test case starting from 1. Then output the number of palindromic numbers you used, n, on one line. n must be no more than 50. en output n lines, each containing one of your palindromic numbers. Their sum must be exactly s.
Sample Input
2 18 1000000000000
Sample Output
Case #1: 2 9 9 Case #2: 2 999999999999 1Hint9 + 9 = 18 999999999999 + 1 = 1000000000000
Source
Recommend
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5920
题目大意:
输入一个长整数s(s<=101000),求将其拆分为不超过50个回文串之和的方案。
题目思路:
【模拟】
将前半段取出来,-1,构造成回文串c,s-=c,直到c=1。
特殊处理0~20的情况。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 2004
using namespace std;
typedef long long LL;
double anss;
LL aans,sum;
int cas,cass;
int n,m,lll,ans;
char s[N];
int a[54][N],b[N],c[N];
void gjdjian(int a[],int b[])
{
int i;
for(i=1;i<=b[0];i++)
a[i]-=b[i];
for(i=1;i<=a[0];i++)
if(a[i]<0)
a[i]+=J,a[i+1]--;
while(a[0]>1 && !a[a[0]])a[0]--;
}
void gjdprint(int a[])
{
int i;
for(i=a[0];i;i--)
printf("%d",a[i]);
puts("");
}
void print()
{
int i,j;
printf("Case #%d:\n",cass);
printf("%d\n",lll);
for(i=1;i<=lll;i++)
gjdprint(a[i]);
}
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
lll=0;mem(a,0);
scanf("%s",s);
n=strlen(s);
b[0]=n;
for(i=0;i<n;i++)b[n-i]=s[i]-'0';
while(!(b[0]==1 && b[1]==0))
{
if(b[0]==1)
{
a[++lll][0]=1;
a[lll][1]=b[1];
break;
}
else if(b[0]==2 && b[2]==1)
{
if(b[1]==0)
{
a[++lll][0]=1;
a[lll][1]=9;
a[++lll][0]=1;
a[lll][1]=1;
break;
}
else if(b[1]==1)
{
a[++lll][0]=2;
a[lll][1]=1;
a[lll][2]=1;
break;
}
else
{
a[++lll][0]=2;
a[lll][1]=1;
a[lll][2]=1;
a[++lll][0]=1;
a[lll][1]=b[1]-1;
break;
}
}
else
{
for(i=b[0];i>b[0]/2;i--)
c[i-b[0]/2]=b[i];
c[0]=(b[0]+1)/2;
int d[2]={1,1};
gjdjian(c,d);
j=c[0]+c[0];
while(j>b[0])j--;
lll++;
a[lll][0]=j;
for(i=c[0];i;i--,j--)
a[lll][c[0]-i+1]=a[lll][j]=c[i];
gjdjian(b,a[lll]);
}
}
print();
}
return 0;
}
/*
//
//
*/
本文介绍了一种算法,用于将一个大整数拆分成若干个回文数的和。通过特殊的构造方法,确保了拆分后的回文数数量不超过50个,适用于竞赛编程中的特定问题。
251

被折叠的 条评论
为什么被折叠?



