Ugly Problem
Ugly Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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≤s≤101000).
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.
18
1000000000000
2
9
9
Case #2:
2
999999999999
1
9 + 9 = 18
999999999999 + 1 = 1000000000000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<ll,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
const int maxn=1e3+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,cnt,cas;
char a[maxn],ans[][maxn];
string gao(string a, string b){
int lena = a.length();
int lenb = b.length();
int len = max(lena, lenb) + ;
char res[len];
memset(res, , sizeof(res));
int flag, reslen = len;
len--;
res[len] = ;
len--;
lena--; lenb--;
flag = ;
while(lenb >= ){
res[len] = a[lena--] - b[lenb--] + '' - flag;
flag = ;
if(res[len] < ''){
flag = ;
res[len] = res[len] + ;
}
len--;
}
while(lena >= ){
res[len] = a[lena--] - flag;
flag = ;
if(res[len] < ''){
flag = ;
res[len] = res[len] + ;
}
len--;
}
while((res[flag] == || res[flag] == '') && flag < reslen) flag++;
if(flag == reslen) return "";
return res + flag;
}
void find(char*p,int now)
{
int i,len=strlen(p);
ans[now][len]=;
for(int i=;i<(len+)/;i++)
ans[now][i]=ans[now][len--i]=p[i];
bool flag=false;
for(int i=len/-;i>=;i--)
{
if(p[i]<p[len--i])break;
else if(p[i]>p[len--i])
{
ans[now][i]--;
ans[now][len--i]--;
for(int j=i+;j<len--i;j++)ans[now][j]=ans[now][len--j]='';
break;
}
}
for(i=;ans[now][i]=='';i++)
{
ans[now][len--i]='';
}
strcpy(ans[now],ans[now]+i);
strcpy(a,gao(p,ans[now]).c_str());
}
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
cnt=;
scanf("%s",a);
while(strcmp(a,"")!=)
{
find(a,cnt);
cnt++;
}
printf("Case #%d:\n%d\n",++cas,cnt);
rep(i,,cnt-)printf("%s\n",ans[i]);
}
//system("Pause");
return ;
}
Ugly Problem的更多相关文章
- hdu-5920 Ugly Problem(贪心+高精度)
题目链接: Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- D - Ugly Problem HDU - 5920
D - Ugly Problem HDU - 5920 Everyone hates ugly problems. You are given a positive integer. You must ...
- 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...
- HDU 5920 Ugly Problem
说起这道题, 真是一把辛酸泪. 题意 将一个正整数 \(n(\le 10^{1000})\) 分解成不超过50个回文数的和. 做法 构造. 队友UHC提出的一种构造方法, 写起来比较方便一些, 而且比 ...
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- HDU - 5920 Ugly Problem 求解第一个小于n的回文数
http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...
- TZOJ 4021 Ugly Problem(线段树区间子段最大)
描述 给定一个序列A[0],A[1],…A[N-1],要求找到p0,p1,p2,p3使得A[p0]+A[p0+1]+…+A[p1] + A[p2]+A[p2+1]+…+A[p3]最大(0<=p0 ...
- 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- 【Sort】QuickSort
快速排序,平均运行时间O(N log N),最坏运行时间O(N^2). 我觉得先看Python版的快排算法(http://www.cnblogs.com/fcyworld/p/6160558.html ...
- Java Object 构造方法的执行顺序
Java Object 构造方法的执行顺序 @author ixenos 为了使用类而做的准备工作包括三个步骤 1)加载:类加载器查找字节码(一般在classpath中找),从字节码创建一个Class ...
- Webpack入门——使用Webpack打包Angular项目的一个例子
2016.1.22,对大多数人来说,这是一个非常平常的日子,但这却是我决定在博客园写博客的日子.虽然注册博客园的博客已有4年8个月,却一直没有动手写过一篇博客,原因是觉得自己水平不行,写不出好东西,所 ...
- Excel教程(9) - 信息函数
CELL 用途:返回某一引用区域的左上角单元格的格式.位置或 内容等信息,该函数主要用于保持与其它电子表格程序的兼容 性. 语法:CELL(info_type,reference) 参数:Info ...
- hdu 1210 Eddy's 洗牌问题
Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于纸牌也有一定的研究,他在无聊时研究发现,如果他有2N张牌,编号为1,2,3..n,n+1,..2n.这也是 ...
- MySQL5.5.源码安装
MySQL5.5.34安装需要用到cmke ncurses-devel yum install -y ncurses-devel cmake gcc gcc-c++ bison 下载http://m ...
- spring配置文件详解【总结】
知其然,知其所以然 <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns=&qu ...
- iOS中的触摸事件,手势识别,摇晃事件等
在iOS中,事件可以划分为以下几类: 1.触摸事件:通过触摸,手势进行触发(手指点击.缩放等) 2.运动事件:通过加速器触发(例如手机晃动) 3.远程控制事件:通过其他远程设备触发(例如耳机控制按钮) ...
- Hash算法冲突解决方法分析
采用开放定址法处理散列表的冲突时,其平均查找长度? 高于链接法处理冲突 低于二分查找 开放定址法:一旦发生冲突,就去寻找下一个空的散列地址,只要散列地址够大,空的地址总会找到 链地址法: 一旦发生冲 ...
- (译)UEFI 启动:实际工作原理
本文是我翻译自国外技术博客的一篇文章,其中讲述了 UEFI 的一些基本概念和细节. 本文的原始链接位于: https://www.happyassassin.net/2014/01/25/uefi-b ...