Ugly Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
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 (1\leq s \leq 10^{1000}).

 
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

 
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5920

题意:将一个数拆成n(n<=50)个回文数的和。
代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[];
int ans[][];
int gg[];
int sub(int t,int len)
{
int i;
for(i=len-; i>=; i--)
{
s[i]=s[i]-''-ans[t][i];
if(s[i]<)
{
s[i]+=+'';
s[i-]-=;
}
else s[i]+='';
}
for(i=; i<len; i++)
if(s[i]!='') break;
return i;
}
int main()
{
int i,j,t,T;
while(scanf("%d",&T)!=EOF)
{
getchar();
for(int asd=; asd<=T; asd++)
{
scanf("%s",s);
memset(ans,,sizeof(ans));
int pre=,len=strlen(s);
t=;
while(pre<len)
{
int sign=;
for(i=pre,j=len-; i<=j; i++,j--)
{
ans[t][i]=ans[t][j]=s[i]-'';
if(ans[t][j]>s[j]-'') sign=;
else if(ans[t][j]<s[j]-'')sign=;
}
gg[t]=pre;
if(sign==)
{
i--;
ans[t][i]-=;
while(i>=&&ans[t][i]<)
{
ans[t][i]+=;
ans[t][i-]-=;
i--;
}
for(i=pre,j=len-; i<=j; i++,j--)
ans[t][j]=ans[t][i];
if(ans[t][pre]==)
{
ans[t][len-]=;
gg[t]=pre+;
}
}
pre=sub(t,len);
t++;
}
printf("Case #%d:\n",asd);
printf("%d\n",t);
for(i=; i<t; i++)
{
for(j=gg[i]; j<len; j++)
printf("%d",ans[i][j]);
printf("\n");
}
}
}
return ;
}

2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟的更多相关文章

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

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  2. HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))

    Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  3. HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  4. HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))

    Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  5. 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree

    Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...

  6. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  7. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 F题 Clever King(最小割)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  8. 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...

  9. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. JavaScript常用小技巧

    1.获取访问地址URL的参数 <script type="text/javascript"> var param = ""; var nowUrl ...

  2. ASP.NET MVC+EF5 开发常用代码

      Asp.Net Mvc,EF 技术常用点总结 1.Asp.Net MVC a)获得当前控制器名和当前操作的名称(action) 1.Action 中 RouteData.Values[" ...

  3. EditText----

    ==============01   editText属性 1.输入法Enter键图标的设置: 软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,a ...

  4. java内存溢出分析(一)

    在项目中发现内存占用过高,且一直不会释放,top命令如下图显示 可以看到pid为17453的java进程占用27.1%内存,且长时间没有释放. 1.使用命令生成heap日志以供分析 sudo jmap ...

  5. [IIS]IIS扫盲(三)

      IIS扫盲贴 --==[精品]==--   IIS扫盲贴     --==[精品]==-- 2000对应iis5.0  xp对应iis5.1  2003对应iis6.0        作者: II ...

  6. 9. Sort List && Insertion Sort List (链表排序总结)

    Sort List Sort a linked list in O(n log n) time using constant space complexity.                   H ...

  7. 10. Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  8. Linux下ejabberd安装配置

    1.下载Ejabberd安装包 wget http://www.process-one.net/downloads/ejabberd/2.1.13/ejabberd-2.1.13-linux-x86_ ...

  9. The trash has reached its maximum size

    From: http://hi.baidu.com/aipie0066/item/1d7fb3e3a4710b3a4cdcaf5e The trash has reached its maximum  ...

  10. Android IOS WebRTC 音视频开发总结(七一)-- H265/H264有何不同

    本文整理自自网络,非原创,喜欢相关文章请关注我们的微信公众号:blackerteam H.265 H.265是ITU-TVCEG继H.264之后所制定的新的视频编码标准.H.265标准围绕着现有的视频 ...