HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

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.
 

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 ( 1s101000 ).
 

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 1
Hint
9 + 9 = 18 999999999999 + 1 = 1000000000000
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5921  5919  5918  5917  5915 
 

Statistic |  Submit |  Discuss |  Note

题目链接:

  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;
}
/*
//

//
*/




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值