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) ...
随机推荐
- HackerRank "Kruskal (MST): Really Special Subtree"
Kruskal Algorithm is based on Union-Find - quite intuitive. #include <vector> #include <ios ...
- swoole和erlang通信测试
直接用docker跑环境 docker pull xlight/docker-php7-swoole docker run -it -v ~/Projects/php/swoole:/workdir ...
- log4net:保存自定义参数到数据库
log4net:保存日志到数据库 自定义参数 新建一个类,继承于PatternLayoutConverter public class CustomerPatternConverter : Patte ...
- HTML标签_01
<!DOCTYPE html> <html> <body> <h1>我的第一个标题</h1> <p>我的第一个段落.</p ...
- java io流 数据流传输
java io流 数据流传输 把这段当公式用就可以了 //数据流传输 import java.io.*; public class Index{ public static void main(Str ...
- Discuz 模板目录
-------------------------------------------------------------------------------------------------- t ...
- .tar.gz文件和.rpm文件的区别
Linux软件的二进制分发是指事先已经编译好二进制形式的软件包的发布形式,其优点是安装使用容易,缺点则是缺乏灵活性,如果该软件包是为特定的硬件/操作系统平台编译的,那它就不能在另外的平台或环境下正确执 ...
- 导入Eclipse工程 到 Android Studio
一.从Eclipse导入工程到Android Studio 根据官方的介绍,Android Studio可以兼容Eclipse的现有工程,但需要做一些操作: 首先升级ADT到最新版本,目前为版本号为2 ...
- BroadcastReceiver和EventBus区别是什么
BroadcastReceiver和EventBus区别是什么?他俩都挺像的,什么时候用BroadcastReceiver,什么时候用EventBus呢? Android广播分为两个方面:广播发送者和 ...
- XE6移动开发环境搭建之IOS篇(4):VMware9里安装Mac OSX 10.8(有图有真相)
网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 以下内容比较长,我们 ...