HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
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 JudgeProblem DescriptionEveryone 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.
InputIn 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).
OutputFor 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 Input2181000000000000Sample OutputCase #1:299Case #2:29999999999991Hint9 + 9 = 18
999999999999 + 1 = 1000000000000Statistic | 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中国大学生程序设计竞赛(长春))的更多相关文章
- 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 ...
- HDU 5916 Harmonic Value Description 【构造】(2016中国大学生程序设计竞赛(长春))
Harmonic Value Description Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- 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 ...
- HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛
/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...
- 2016中国大学生程序设计竞赛(长春)-重现赛 1010Ugly Problem 回文数 模拟
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1001 A water problem (大数取余)
Problem Descripton Two planets named Haha and Xixi in the universe and they were created with the un ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa
Problem Description Chisa Yukizome works as a teacher in the school. She prepares many gifts, which ...
随机推荐
- Oracle 的merge into 用法
1.merge into的用途 Merge是一个非常有用的功能,与DB2中的merge into功能几乎一样,与Mysql里的insert into on duplicate key也很类似.MERG ...
- CollectionView就是这么简单!
UICollectionView 和 UICollectionViewController 类是iOS6 新引进的API,用于展示集合视图,布局更加灵活,可实现多列布局,用法类似于UITableVie ...
- javascript闭包传参和事件的循环绑定
今天看到一个javascript的题目,按常理循环绑定事件,但是得到的结果却不是想要的. <a href="#">text</a><br>< ...
- ajax 异步上传视频带进度条并提取缩略图
最近在做一个集富媒体功能于一身的项目.需要上传视频.这里我希望做成异步上传,并且有进度条,响应有状态码,视频连接,缩略图. 服务端响应 { "thumbnail": "/ ...
- strtotime 的几点不同
在php里面,strtotime()有点比较特殊,date函数也有点问题 if ( date(1,time()) == "Monday") //似乎 date(1,time( ...
- supervisor进程管理
install : apt-get install supervisor crete a xxxx.conf file at /etc/supervisor/conf.d the cont ...
- chmod 命令
来源网址: http://www.2cto.com/os/201205/130236.html http://www.cnblogs.com/younes/archive/2009/11/20/160 ...
- Xcode-程序开发设计-02九宫格
行号是除 决定Y值 列号是余 决定X值 // // ViewController.m // 06-应用管理 // // Created by daier on 15/12/31. // Copyrig ...
- 阿里云ECS服务器配置ubuntu安装openfire服务器
最近搞了一台阿里云的ECS服务器,因为搞活动半年免费,所以就申请了一台,过两天就批准下来,顺便多花了1百多RMB买了固定IP.总体说来还是挺值的,觉得一个人用挺浪费,分享出来跟大家一起玩玩. 搞台服务 ...
- Socket 错误总结
错误 因为并没有搞清楚accept函数的使用,所以导致不停的发送失败,同时还不知道错误在哪里,无意中看见errno这个库,可以记录错误的原因,才知道原因在于没有用客户端的套接字进行接收数据,而这个客户 ...