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≤s≤101000).

 
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
 

Statistic | Submit | Clarifications | Back

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5920

题目大意:

  输入一个长整数s(s<=101000),求将其拆分为不超过50个回文串之和的方案。

题目思路:

  【模拟】

  将前半段取出来,-1,构造成回文串c,s-=c,直到c=1。

  特殊处理0~20的情况。

 //
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 2004
using namespace std;
typedef long long LL;
double anss;
LL aans,sum;
int cas,cass;
int n,m,lll,ans;
char s[N];
int a[][N],b[N],c[N];
void gjdjian(int a[],int b[])
{
int i;
for(i=;i<=b[];i++)
a[i]-=b[i];
for(i=;i<=a[];i++)
if(a[i]<)
a[i]+=J,a[i+]--;
while(a[]> && !a[a[]])a[]--;
}
void gjdprint(int a[])
{
int i;
for(i=a[];i;i--)
printf("%d",a[i]);
puts("");
}
void print()
{
int i,j;
printf("Case #%d:\n",cass);
printf("%d\n",lll);
for(i=;i<=lll;i++)
gjdprint(a[i]);
}
int main()
{
#ifndef ONLINE_JUDGEW
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
{
lll=;mem(a,);
scanf("%s",s);
n=strlen(s);
b[]=n;
for(i=;i<n;i++)b[n-i]=s[i]-'';
while(!(b[]== && b[]==))
{
if(b[]==)
{
a[++lll][]=;
a[lll][]=b[];
break;
}
else if(b[]== && b[]==)
{
if(b[]==)
{
a[++lll][]=;
a[lll][]=;
a[++lll][]=;
a[lll][]=;
break;
}
else if(b[]==)
{
a[++lll][]=;
a[lll][]=;
a[lll][]=;
break;
}
else
{
a[++lll][]=;
a[lll][]=;
a[lll][]=;
a[++lll][]=;
a[lll][]=b[]-;
break;
}
}
else
{
for(i=b[];i>b[]/;i--)
c[i-b[]/]=b[i];
c[]=(b[]+)/;
int d[]={,};
gjdjian(c,d);
j=c[]+c[];
while(j>b[])j--;
lll++;
a[lll][]=j;
for(i=c[];i;i--,j--)
a[lll][c[]-i+]=a[lll][j]=c[i];
gjdjian(b,a[lll]);
}
}
print();
}
return ;
}
/*
// //
*/

HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))的更多相关文章

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

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

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

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

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

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

  4. 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 ...

  5. HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    /* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...

  6. 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟

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

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

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

  8. 2016中国大学生程序设计竞赛 - 网络选拔赛 1001 A water problem (大数取余)

    Problem Descripton Two planets named Haha and Xixi in the universe and they were created with the un ...

  9. 2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa

    Problem Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which ...

随机推荐

  1. C++ 常见问题

    1:保证编译后方法名不被修改:  The: extern "C" { function declarations here in h file } will disable C++ ...

  2. 深入理解自定义ListView

    深入理解自定义ListView ListView原理 他是一个系统的原生控件,用列表的形式来显示内容.如果内容过过有1000条左右,我们可以通过手势的上下滑动来查看数据.ListView也不是爆出OO ...

  3. C#之垃圾回收

    垃圾回收时现代语言的标志之一.垃圾回收解放了手工管理对象释放的工作,提高了程序的健壮性,但是副作用就是程序代码可以对于创建对象变得随意. 1.避免不必要的对象创建 由于垃圾回收的代价较高,所以C#程序 ...

  4. C#中的委托范例学习

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  5. MyBatis的学习总结六:Mybatis的缓存【参考】

    一.Mybatis缓存介绍 正如大多数持久层框架一样,Mybatis同样提供了一级缓存和二级缓存 1.一级缓存:基于PerpetualCache的HashMap本地缓存,其存储作用域为Session, ...

  6. UITableView中容易忽略的知识点

    1.取消余下的分割线 tableView.tableFooterView = UIView() 2.分割线顶格 override func viewDidLayoutSubviews() { self ...

  7. CSV文件规则

    CSV文件规则 1 开头是不留空,以行为单位.2 可含或不含列名,含列名则居文件第一行.3 一行数据不跨行,无空行.4 以半角逗号(即,)作分隔符,列为空也要表达其存在.5 列内容如存在半角逗号(即, ...

  8. Gulp(一)

    一.简介 gulp 是基于 Nodejs 的自动任务运行器,能自动化地完成javascript/coffee/sass/less/html/image/css等文件的的测试.检查.合并.压缩.格式化. ...

  9. C++ trivial和non-trivial构造函数及POD类型(转)

    原博客地址http://blog.csdn.net/a627088424/article/details/48595525 最近正纠结这个问题就转过来了,做了点补充(参考<深度探索C++对象模型 ...

  10. Linux 权限基础说明

      1 权限位说明 Linux文件或目录的权限位是由个9个权限位来控制的,每三位为一组,它们分别是文件属主(owner/user)读.写.执行,用户组(Group)的读.写.执行以及(Other)其他 ...