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. 解决如下json格式的字符串不能使用DataContractJsonSerializer序列化和反序列化 分类: JSON 2015-01-28 14:26 72人阅读 评论(0) 收藏

    可以解决如下json格式的字符串不能使用DataContractJsonSerializer反序列化 {     "ss": "sss",     " ...

  2. 利用jquery实现百度新闻导航菜单滑动动画

    前言 前两天,群里有人问百度新闻导航是如何实现的,当时由于忙于工作,没有来得及细看,恰好今天有空闲时间,索性就实现一下这个效果吧: 思路与步骤 1.利用UL创建简单横向导航: <!DOCTYPE ...

  3. python基础知识二

    对象 python把在程序中用到的任何东西都成为对象. 每一个东西包括数.字符串甚至函数都是对象. 使用变量时只需要给他们赋一个值.不需要声明或定义数据类型. 逻辑行与物理行 物理行是你在编写程序时所 ...

  4. 如何在ASP.NET 项目中使用Silverlight页面

    闲来无事,想写个网站玩玩,比较懒,不想写太多的样式来美化,看中了Silverlight,样式布局比较省事,但是又不想全部都用Silverlight 来写,所以才有此一文. 其实Silverlight最 ...

  5. SQL Server 索引和视图【转】

    Ø 索引 1. 什么是索引 索引就是数据表中数据和相应的存储位置的列表,利用索引可以提高在表或视图中的查找数据的速度. 2. 索引分类 数据库中索引主要分为两类:聚集索引和非聚集索引.SQL Serv ...

  6. winform程序中界面的跳转问题

    首先是我们进行窗口间的跳转,尤其注意的是winform程序里面的空间都是中线程安全的.但是注意的是如果你在一个线程中操纵另外的控件,这时候会提示你一个错误,这个错误的解决方法准备单独的在另一篇文章中来 ...

  7. 【实习记】2014-08-23网络安全XSS与CSRF总结

        XSS:脚本中的不速之客XSS:跨站脚本(Cross-site scripting)CSRF:冒充用户之手CSRF:跨站请求伪造(Cross-site request forgery) 谷歌搜 ...

  8. http与https差异

    HTTPS和HTTP的区别: https协议需要到ca申请证书,一般免费证书很少,需要交费. http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议 http的连接很 ...

  9. WPF Window异形窗口演示

    我们先通过简单的效果展示,切换展示不同图片: 我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义: <Application x:Class=" ...

  10. JSP特点

    建立在servlet规范功能之上的动态网页技术. JSP文件在用户第一次请求时,会被编译成servlet,然后由servlet处理用户的请求.所以JSP可以看成运行时servlet. 1).将内容的生 ...