2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
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
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.
For each test case, there is only one line describing the given integer s (1\leq s \leq 10^{1000}).
9 + 9 = 18 999999999999 + 1 = 1000000000000
#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 回文数 模拟的更多相关文章
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))
Fraction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- 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 ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 F题 Clever King(最小割)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- JavaScript常用小技巧
1.获取访问地址URL的参数 <script type="text/javascript"> var param = ""; var nowUrl ...
- ASP.NET MVC+EF5 开发常用代码
Asp.Net Mvc,EF 技术常用点总结 1.Asp.Net MVC a)获得当前控制器名和当前操作的名称(action) 1.Action 中 RouteData.Values[" ...
- EditText----
==============01 editText属性 1.输入法Enter键图标的设置: 软件盘的界面替换只有一个属性android:imeOptions,这个属性的可以取的值有normal,a ...
- java内存溢出分析(一)
在项目中发现内存占用过高,且一直不会释放,top命令如下图显示 可以看到pid为17453的java进程占用27.1%内存,且长时间没有释放. 1.使用命令生成heap日志以供分析 sudo jmap ...
- [IIS]IIS扫盲(三)
IIS扫盲贴 --==[精品]==-- IIS扫盲贴 --==[精品]==-- 2000对应iis5.0 xp对应iis5.1 2003对应iis6.0 作者: II ...
- 9. Sort List && Insertion Sort List (链表排序总结)
Sort List Sort a linked list in O(n log n) time using constant space complexity. H ...
- 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. ...
- Linux下ejabberd安装配置
1.下载Ejabberd安装包 wget http://www.process-one.net/downloads/ejabberd/2.1.13/ejabberd-2.1.13-linux-x86_ ...
- The trash has reached its maximum size
From: http://hi.baidu.com/aipie0066/item/1d7fb3e3a4710b3a4cdcaf5e The trash has reached its maximum ...
- Android IOS WebRTC 音视频开发总结(七一)-- H265/H264有何不同
本文整理自自网络,非原创,喜欢相关文章请关注我们的微信公众号:blackerteam H.265 H.265是ITU-TVCEG继H.264之后所制定的新的视频编码标准.H.265标准围绕着现有的视频 ...