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. HackerRank "Kruskal (MST): Really Special Subtree"

    Kruskal Algorithm is based on Union-Find - quite intuitive. #include <vector> #include <ios ...

  2. swoole和erlang通信测试

    直接用docker跑环境 docker pull xlight/docker-php7-swoole docker run -it -v ~/Projects/php/swoole:/workdir ...

  3. log4net:保存自定义参数到数据库

    log4net:保存日志到数据库 自定义参数 新建一个类,继承于PatternLayoutConverter public class CustomerPatternConverter : Patte ...

  4. HTML标签_01

    <!DOCTYPE html> <html> <body> <h1>我的第一个标题</h1> <p>我的第一个段落.</p ...

  5. java io流 数据流传输

    java io流 数据流传输 把这段当公式用就可以了 //数据流传输 import java.io.*; public class Index{ public static void main(Str ...

  6. Discuz 模板目录

    -------------------------------------------------------------------------------------------------- t ...

  7. .tar.gz文件和.rpm文件的区别

    Linux软件的二进制分发是指事先已经编译好二进制形式的软件包的发布形式,其优点是安装使用容易,缺点则是缺乏灵活性,如果该软件包是为特定的硬件/操作系统平台编译的,那它就不能在另外的平台或环境下正确执 ...

  8. 导入Eclipse工程 到 Android Studio

    一.从Eclipse导入工程到Android Studio 根据官方的介绍,Android Studio可以兼容Eclipse的现有工程,但需要做一些操作: 首先升级ADT到最新版本,目前为版本号为2 ...

  9. BroadcastReceiver和EventBus区别是什么

    BroadcastReceiver和EventBus区别是什么?他俩都挺像的,什么时候用BroadcastReceiver,什么时候用EventBus呢? Android广播分为两个方面:广播发送者和 ...

  10. XE6移动开发环境搭建之IOS篇(4):VMware9里安装Mac OSX 10.8(有图有真相)

    网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 以下内容比较长,我们 ...