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. JS 时间格式化函数

    //时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...

  2. 覆盖(override)和重载(overload)

    覆盖(override)重写和 重载(overload) 继承,重写--->多态   我懂了,你懂吗 ,不看看文章 java 子类重写父类的方法应注意的问题 Java多态性理解

  3. js--小结⑤

    js中的for循环,while循环,do...while循环和C语言的一模一样 有几个问题要提醒一下的是 1.  null是对象,即object       undefined是undefined d ...

  4. 使用原生JS编写ajax操作XMLHttpRequst对象

    ajax其本质就是XMLHttpRequest,现在jquery调用异步的方法很方便,但是也不能忘记原生的JS去编写ajax; 需要注意的是,很多人在写的时候喜欢只用XMLHttpRequest对象r ...

  5. SQLServer2008找出所有包含172.17.224.40字样的存储过程

    SQLServer2008 找出所有包含172.17.224.40的存储过程   select distinct name from syscomments a,sysobjects b where ...

  6. $(obj).data() 绑定和获取数据的应用

    1.解说 data() 方法向被选元素附加数据,或者从被选元素获取数据. 例如:$("#id").data("name","xiao"); ...

  7. ios专题 - 多线程非GCD(1)

    iOS多线程初体验是本文要介绍的内容,iPhone中的线程应用并不是无节制的,官方给出的资料显示iPhone OS下的主线程的堆栈大小是1M,第二个线程开始都是512KB.并且该值不能通过编译器开关或 ...

  8. SQLITE和QT

    sqlite3数据库支持事务 例如: BEGIN DEFERRED TRANSACTION; INSERT INTO main.test_transaction (test_unique) VALUE ...

  9. easy ui tree 取父节点的值和取蓝色框的值

    var nodes = $('#basetree').tree('getChecked'); var cnode = ''; var fnode = ''; for ( var i = 0; i &l ...

  10. 受教了,memcache比较全面点的介绍,受益匪浅,适用memcached的业务场景有哪些?memcached的cache机制是怎样的?在设计应用时,可以通过Memcached缓存那些内容?

    基本问题 1.memcached的基本设置 1)启动Memcache的服务器端 # /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 ...